Completed
Pull Request — master (#290)
by
unknown
41:51
created

Address   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 138
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A createFromArray() 0 19 1
A firstName() 0 4 1
A lastName() 0 4 1
A city() 0 4 1
A street() 0 4 1
A countryCode() 0 4 1
A postcode() 0 4 1
A provinceName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\SyliusShopApiPlugin\Model;
6
7
use Webmozart\Assert\Assert;
8
9
final class Address
10
{
11
    /**
12
     * @var string
13
     */
14
    private $firstName;
15
16
    /**
17
     * @var string
18
     */
19
    private $lastName;
20
21
    /**
22
     * @var string
23
     */
24
    private $city;
25
26
    /**
27
     * @var string
28
     */
29
    private $countryCode;
30
31
    /**
32
     * @var string
33
     */
34
    private $street;
35
36
    /**
37
     * @var string
38
     */
39
    private $postcode;
40
41
    /**
42
     * @var string
43
     */
44
    private $provinceName;
45
46
    /**
47
     * @param string $firstName
48
     * @param string $lastName
49
     * @param string $city
50
     * @param string $street
51
     * @param string $countryCode
52
     * @param string $postcode
53
     * @param string $provinceName
54
     */
55
    private function __construct($firstName, $lastName, $city, $street, $countryCode, $postcode, $provinceName = null)
56
    {
57
        $this->firstName = $firstName;
58
        $this->lastName = $lastName;
59
        $this->city = $city;
60
        $this->street = $street;
61
        $this->countryCode = $countryCode;
62
        $this->postcode = $postcode;
63
        $this->provinceName = $provinceName;
64
    }
65
66
    /**
67
     * @param array $address
68
     *
69
     * @return Address
70
     */
71
    public static function createFromArray(array $address)
72
    {
73
        Assert::keyExists($address, 'firstName');
74
        Assert::keyExists($address, 'lastName');
75
        Assert::keyExists($address, 'city');
76
        Assert::keyExists($address, 'street');
77
        Assert::keyExists($address, 'countryCode');
78
        Assert::keyExists($address, 'postcode');
79
80
        return new self(
81
            $address['firstName'],
82
            $address['lastName'],
83
            $address['city'],
84
            $address['street'],
85
            $address['countryCode'],
86
            $address['postcode'],
87
            $address['provinceName'] ?? null
88
        );
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function firstName()
95
    {
96
        return $this->firstName;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function lastName()
103
    {
104
        return $this->lastName;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function city()
111
    {
112
        return $this->city;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function street()
119
    {
120
        return $this->street;
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function countryCode()
127
    {
128
        return $this->countryCode;
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function postcode()
135
    {
136
        return $this->postcode;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function provinceName()
143
    {
144
        return $this->provinceName;
145
    }
146
}
147