Address   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 68
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A value() 0 3 1
A __construct() 0 6 1
A getFullAddress() 0 3 1
A format() 0 7 1
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