| Total Complexity | 5 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | abstract class FloatValueObject implements FloatValueObjectInterface |
||
| 12 | { |
||
| 13 | private $value; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @throws Exception if value is invalid |
||
| 17 | */ |
||
| 18 | public function __construct(float $value) |
||
| 19 | { |
||
| 20 | try { |
||
| 21 | $this->guard($value); |
||
| 22 | } catch (Throwable $e) { |
||
| 23 | throw $this->throwException($value, $e); |
||
| 24 | } |
||
| 25 | $this->value = $value; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function equals(FloatValueObjectInterface $other): bool |
||
| 29 | { |
||
| 30 | if (static::class !== get_class($other)) { |
||
| 31 | return false; |
||
| 32 | } |
||
| 33 | return $this->getValue() === $other->getValue(); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function getValue(): float |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @throws Throwable if value is invalid |
||
| 43 | */ |
||
| 44 | abstract protected function guard(float $value): void; |
||
| 45 | |||
| 46 | abstract protected function throwException(float $value, Throwable $e): Exception; |
||
| 47 | } |
||
| 48 |