Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added instructions.md
Empty file.
32 changes: 32 additions & 0 deletions src/Circle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

class Circle extends Shape {

const SHAPE_TYPE = 3;
protected $radius;

/*
Constructor accepts a radius parameter and intializes $radius.
*/
function __construct($radius) {
parent::__construct($length = null, $width = null);
$this->radius = $radius;
}

/*
area method to calculate and return the area of the circle (PI x r x r)
*/
public function area() {
$pi = pi();
$area = $pi * pow($this->radius, 2);
return $area;
}

/*
getFullDescription method to return string describing the shape
Uses getId() to get the Id because that's a protected property of the parent class
*/
public function getFullDescription() {
return get_class($this) . '<#' . $this->getId() . '>: ' . $this->name . ' - ' . $this->radius;
}
}
7 changes: 7 additions & 0 deletions src/Rectangle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Rectangle extends Shape {
const SHAPE_TYPE = 2;

//Rectangle class should not require any additional properties or methods, as it inherits them from Shape class.
}
58 changes: 58 additions & 0 deletions src/Shape.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

class Shape {

const SHAPE_TYPE = 1;
public $name;
protected $length;
protected $width;
private $id;

function __construct($length, $width) {
$this->length = $length;
$this->width = $width;
$this->id = uniqid();
}

/*
Getter and Setter methods for $name property
*/
function getName() {
return $this->name;
}

function setName($name) {
$this->name = $name;
return $name;
}

/*
Getter method for $id property
*/
function getId() {
return $this->id;
}

/*
Area method to calculate and return the area of the Shape object
*/
public function area() {
$area = $this->length * $this->width;
return $area;
}

/*
getTypeDescription method to return the shape type
*/
public static function getTypeDescription() {
return 'Type: ' . static::SHAPE_TYPE;
}

/*
getFullDescription method to return string describing the shape
*/
public function getFullDescription() {
return get_class($this) . '<#' . $this->id . '>: ' . $this->name . ' - ' . $this->length . ' x ' . $this->width;
}

}