1 | <?php |
||
22 | class Rectangle |
||
23 | { |
||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | private $iWidth; |
||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $iHeight; |
||
32 | |||
33 | /** |
||
34 | * Rectangle constructor. |
||
35 | * |
||
36 | * @param int $w |
||
37 | * @param int|null $h |
||
38 | */ |
||
39 | 4 | public function __construct(int $w, int $h = null) |
|
40 | { |
||
41 | 4 | $this->iWidth = $w < 0 ? 0 : $w; |
|
42 | 4 | $this->iHeight = $h < 0 ? 0 : ($h ?? $this->iWidth); |
|
43 | 4 | } |
|
44 | |||
45 | /** |
||
46 | * @return int |
||
47 | */ |
||
48 | 3 | public function getArea() |
|
52 | |||
53 | /** |
||
54 | * @return int |
||
55 | */ |
||
56 | 3 | public function getHeight() |
|
60 | |||
61 | /** |
||
62 | * @return int |
||
63 | */ |
||
64 | 3 | public function getWidth() |
|
68 | } |
||
69 |