Skip to content

Commit c72d413

Browse files
author
Tomáš Votruba
authored
Merge pull request piotrplenik#106 from mcustiel/master
Proposal to fix issue piotrplenik#37
2 parents 77c0a5b + b133b4f commit c72d413

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

README.md

+7-18
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,6 @@ renderLargeRectangles($rectangles);
17291729
```php
17301730
abstract class Shape
17311731
{
1732-
protected $width = 0;
1733-
protected $height = 0;
1734-
17351732
abstract public function getArea(): int;
17361733

17371734
public function render(int $area): void
@@ -1742,13 +1739,12 @@ abstract class Shape
17421739

17431740
class Rectangle extends Shape
17441741
{
1745-
public function setWidth(int $width): void
1746-
{
1747-
$this->width = $width;
1748-
}
1742+
private $width;
1743+
private $height;
17491744

1750-
public function setHeight(int $height): void
1745+
public function __construct(int $width, int $height)
17511746
{
1747+
$this->width = $width;
17521748
$this->height = $height;
17531749
}
17541750

@@ -1760,9 +1756,9 @@ class Rectangle extends Shape
17601756

17611757
class Square extends Shape
17621758
{
1763-
private $length = 0;
1759+
private $length;
17641760

1765-
public function setLength(int $length): void
1761+
public function __construct(int $length)
17661762
{
17671763
$this->length = $length;
17681764
}
@@ -1779,19 +1775,12 @@ class Square extends Shape
17791775
function renderLargeRectangles(array $rectangles): void
17801776
{
17811777
foreach ($rectangles as $rectangle) {
1782-
if ($rectangle instanceof Square) {
1783-
$rectangle->setLength(5);
1784-
} elseif ($rectangle instanceof Rectangle) {
1785-
$rectangle->setWidth(4);
1786-
$rectangle->setHeight(5);
1787-
}
1788-
17891778
$area = $rectangle->getArea();
17901779
$rectangle->render($area);
17911780
}
17921781
}
17931782

1794-
$shapes = [new Rectangle(), new Rectangle(), new Square()];
1783+
$shapes = [new Rectangle(4, 5), new Rectangle(4, 5), new Square(5)];
17951784
renderLargeRectangles($shapes);
17961785
```
17971786

0 commit comments

Comments
 (0)