Total Complexity | 6 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | class City extends ValueObject |
||
11 | { |
||
12 | /** |
||
13 | * @var string|null |
||
14 | */ |
||
15 | protected ?string $city = null; |
||
16 | |||
17 | /** |
||
18 | * @var Country|null |
||
19 | */ |
||
20 | protected ?Country $country = null; |
||
21 | |||
22 | /** |
||
23 | * @param array|null $data |
||
24 | */ |
||
25 | 27 | final public function __construct(?array $data) |
|
26 | { |
||
27 | 27 | $this->city = $data['city'] ?? null; |
|
28 | |||
29 | 27 | if (isset($data['country_code'])) { |
|
30 | 8 | $this->country = new Country($data); |
|
31 | } |
||
32 | |||
33 | 27 | $this->sanitizeCity(); |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | 22 | public function value(): string |
|
40 | { |
||
41 | 22 | return $this->city ?? ''; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return void |
||
46 | */ |
||
47 | 27 | protected function sanitizeCity(): void |
|
48 | { |
||
49 | 27 | if (! is_null($this->city)) { |
|
50 | 18 | $this->city = Str::squish($this->city); |
|
51 | } |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | 22 | public function __toString(): string |
|
60 | } |
||
61 | } |
||
62 |