Total Complexity | 5 |
Total Lines | 68 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | class Address extends ValueObject |
||
11 | { |
||
12 | /** |
||
13 | * @var Street |
||
14 | */ |
||
15 | protected Street $street; |
||
16 | |||
17 | /** |
||
18 | * @var PostCode |
||
19 | */ |
||
20 | protected PostCode $postcode; |
||
21 | |||
22 | /** |
||
23 | * @var City |
||
24 | */ |
||
25 | protected City $city; |
||
26 | |||
27 | /** |
||
28 | * @var Country |
||
29 | */ |
||
30 | protected Country $country; |
||
31 | |||
32 | /** |
||
33 | * @param array|null $data |
||
34 | */ |
||
35 | 18 | final public function __construct(?array $data) |
|
36 | { |
||
37 | 18 | $this->country = new Country($data); |
|
38 | 18 | $this->street = new Street($data); |
|
39 | 18 | $this->city = new City($data); |
|
40 | 18 | $this->postcode = new PostCode($data); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return string |
||
45 | */ |
||
46 | 1 | public function value(): string |
|
47 | { |
||
48 | 1 | return $this->getFullAddress(); |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | 16 | public function getFullAddress(): string |
|
55 | { |
||
56 | 16 | return $this->format(); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return string |
||
61 | */ |
||
62 | 16 | protected function format(): string |
|
63 | { |
||
64 | 16 | return format(AddressFormatter::class, [ |
|
65 | 16 | 'country' => (string) $this->country, |
|
66 | 16 | 'street' => (string) $this->street, |
|
67 | 16 | 'city' => (string) $this->city, |
|
68 | 16 | 'postcode' => (string) $this->postcode, |
|
69 | 16 | ]); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | 1 | public function __toString(): string |
|
78 | } |
||
79 | } |
||
80 |