Total Complexity | 5 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | abstract class StringValueObject implements StringValueObjectInterface |
||
12 | { |
||
13 | private $value; |
||
14 | |||
15 | /** |
||
16 | * @throws Exception if value is invalid |
||
17 | */ |
||
18 | public function __construct(string $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(StringValueObjectInterface $other): bool |
||
34 | } |
||
35 | |||
36 | public function getValue(): string |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @throws Throwable if value is invalid |
||
43 | */ |
||
44 | abstract protected function guard(string $value): void; |
||
45 | |||
46 | abstract protected function throwException(string $value, Throwable $e): Exception; |
||
47 | } |
||
48 |