Lines
100.00%
9 / 9
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| equals | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| asFloat | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| validate | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| 11 | readonly class Area | |
| 12 | { | |
| 13 | #[ORM\Column(type: "float")] | |
| 14 | private float $area; | |
| 15 | ||
| 16 | public function __construct(float $area) | |
| 17 | { | |
| 18 | if (!self::validate($area)) { | |
| 19 | throw new InvalidAreaException(); | |
| 20 | } | |
| 21 | $this->area = $area; | |
| 22 | } | |
| 23 | ||
| 24 | public function __toString(): string | |
| 25 | { | |
| 26 | return strval($this->area); | |
| 27 | } | |
| 28 | ||
| 29 | public function equals(self $other): bool | |
| 30 | { | |
| 31 | return $this->area === $other->area; | |
| 32 | } | |
| 33 | ||
| 34 | public function asFloat(): float | |
| 35 | { | |
| 36 | return $this->area; | |
| 37 | } | |
| 38 | ||
| 39 | private static function validate(float $area): bool | |
| 40 | { | |
| 41 | if ($area <= 0) { | |
| 42 | return false; | |
| 43 | } | |
| 44 | return true; | |
| 45 | } | |
| 46 | } |