Lines
100.00%
9 / 9
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Area | 100.00% | 9 / 9 | 100.00% | 5 / 5 | 7 | 100.00% | 1 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Districts\Core\Domain; | |
| 6 | ||
| 7 | use Districts\Core\Domain\Exception\InvalidAreaException; | |
| 8 | use Doctrine\ORM\Mapping as ORM; | |
| 9 | ||
| 10 | #[ORM\Embeddable] | |
| 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 | } |