Address::getFullAddress()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Temidaio\ValueObjects;
6
7
use MichaelRubel\ValueObjects\ValueObject;
8
use Temidaio\ValueObjects\Formatters\AddressFormatter;
9
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
76
    {
77 1
        return $this->value();
78
    }
79
}
80