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
26 changes: 26 additions & 0 deletions src/Circle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

class Circle extends Shape {

// class constants
const SHAPE_TYPE = 3;

// property declarations
private $id;
protected $radius;

// method declarations
public function __construct( $radius ) {
parent::__construct();
$this->radius = $radius;
$this->id = uniqid();
}

public function area() {
return M_PI * $this->radius * $this->radius;
}

} // end class

?>

11 changes: 11 additions & 0 deletions src/Rectangle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

class Rectangle extends Shape {

// class constants
const SHAPE_TYPE = 2;

} // end class

?>

62 changes: 62 additions & 0 deletions src/Shape.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

class Shape {

// class constants
const SHAPE_TYPE = 1;

// property declarations
public $name;
protected $length;
protected $width;
private $id;

// method declarations
public function __construct ( $length = 0, $width = 0 ) {
$this->length = $length;
$this->width = $width;
$this->id = uniqid();
}

public function getName() {
return $this->name;
}

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

public function getId() {
return $this->id;
}

public function area() {
return $this->length * $this->width;
}

static public function getTypeDescription() {
return "Type: " . static::SHAPE_TYPE;
}

public function getFullDescription() {
switch (static::SHAPE_TYPE) {
case 1: // case of SHAPE
$shapeName = "Shape";
$postfix = "<#" . $this->id . ">: " . $this->name . " - " . $this->length . " x " . $this->width;
break;
case 2: // case of RECTANGLE
$shapeName = "Rectangle";
$postfix = "<#" . $this->id . ">: " . $this->name . " - " . $this->length . " x " . $this->width;
break;
case 3: // case of CIRCLE
$shapeName = "Circle";
$postfix = "<#" . $this->id . ">: " . $this->name . " - " . $this->radius;
break;
} // end switch

return $shapeName . $postfix;
}

} // end class

?>