Completed
Push — master ( 290f71...5c7d58 )
by Tobias
01:52
created

Customer   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 340
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 33.03%

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 3
dl 0
loc 340
ccs 36
cts 109
cp 0.3303
rs 9.3999
c 0
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCustomerNo() 0 4 1
A withCustomerNo() 0 7 1
A getName() 0 4 1
A getNotes() 0 4 1
A getOrgNo() 0 4 1
A getVatNo() 0 4 1
A getContact() 0 4 1
A getAddress() 0 4 1
A getDeliveryAddress() 0 4 1
A getCompanyType() 0 4 1
A getCreatedAt() 0 4 1
A getUpdatedAt() 0 4 1
A setUpdatedAt() 0 4 1
A withName() 0 7 1
A withNotes() 0 7 1
A withOrgNo() 0 7 1
A withVatNo() 0 7 1
A withContact() 0 7 1
A withAddress() 0 7 1
A withDeliveryAddress() 0 7 1
A withCompanyType() 0 7 1
B createFromArray() 0 34 2
F toArray() 0 30 9
1
<?php
2
3
namespace Billogram\Model\Customer;
4
5
use Billogram\Model\CreatableFromArray;
6
7
/**
8
 * @author Ibrahim Hizeoui <[email protected]>
9
 */
10
class Customer implements CreatableFromArray
11
{
12
    /**
13
     * @var int
14
     */
15
    private $customerNo;
16
17
    /**
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * @var string
24
     */
25
    private $notes;
26
27
    /**
28
     * @var string
29
     */
30
    private $orgNo;
31
32
    /**
33
     * @var string
34
     */
35
    private $vatNo;
36
37
    /**
38
     * @var CustomerContact
39
     */
40
    private $contact;
41
42
    /**
43
     * @var CustomerBillingAddress
44
     */
45
    private $address;
46
47
    /**
48
     * @var CustomerDeliveryAddress
49
     */
50
    private $deliveryAddress;
51
52
    /**
53
     * @var \DateTime
54
     */
55
    private $createdAt;
56
57
    /**
58
     * @var \DateTime
59
     */
60
    private $updatedAt;
61
62
    /**
63
     * @var string
64
     */
65
    private $companyType;
66
67 4
    public function __construct()
68
    {
69 4
    }
70
71
    /**
72
     * @return int
73
     */
74
    public function getCustomerNo()
75
    {
76
        return $this->customerNo;
77
    }
78
79
    /**
80
     * @param int $customerNo
81
     *
82
     * @return Customer
83
     */
84 2
    public function withCustomerNo(int $customerNo)
85
    {
86 2
        $new = clone $this;
87 2
        $new->customerNo = $customerNo;
88
89 2
        return $new;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getName()
96
    {
97
        return $this->name;
98
    }
99
100
    /**
101
     * @param string $name
102
     *
103
     * @return Customer
104
     */
105
    public function withName(string $name)
106
    {
107
        $new = clone $this;
108
        $new->name = $name;
109
110
        return $new;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getNotes()
117
    {
118
        return $this->notes;
119
    }
120
121
    /**
122
     * @param string $notes
123
     *
124
     * @return Customer
125
     */
126
    public function withNotes(string $notes)
127
    {
128
        $new = clone $this;
129
        $new->notes = $notes;
130
131
        return $new;
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    public function getOrgNo()
138
    {
139
        return $this->orgNo;
140
    }
141
142
    /**
143
     * @param string $orgNo
144
     *
145
     * @return Customer
146
     */
147
    public function withOrgNo(string $orgNo)
148
    {
149
        $new = clone $this;
150
        $new->orgNo = $orgNo;
151
152
        return $new;
153
    }
154
155
    /**
156
     * @return string
157
     */
158
    public function getVatNo()
159
    {
160
        return $this->vatNo;
161
    }
162
163
    /**
164
     * @param string $vatNo
165
     *
166
     * @return Customer
167
     */
168
    public function withVatNo(string $vatNo)
169
    {
170
        $new = clone $this;
171
        $new->vatNo = $vatNo;
172
173
        return $new;
174
    }
175
176
    /**
177
     * @return CustomerContact
178
     */
179
    public function getContact()
180
    {
181
        return $this->contact;
182
    }
183
184
    /**
185
     * @param CustomerContact $contact
186
     *
187
     * @return Customer
188
     */
189
    public function withContact(CustomerContact $contact)
190
    {
191
        $new = clone $this;
192
        $new->contact = $contact;
193
194
        return $new;
195
    }
196
197
    /**
198
     * @return CustomerBillingAddress
199
     */
200
    public function getAddress()
201
    {
202
        return $this->address;
203
    }
204
205
    /**
206
     * @param CustomerBillingAddress $address
207
     *
208
     * @return Customer
209
     */
210
    public function withAddress(CustomerBillingAddress $address)
211
    {
212
        $new = clone $this;
213
        $new->address = $address;
214
215
        return $new;
216
    }
217
218
    /**
219
     * @return CustomerDeliveryAddress
220
     */
221
    public function getDeliveryAddress()
222
    {
223
        return $this->deliveryAddress;
224
    }
225
226
    /**
227
     * @param CustomerDeliveryAddress $deliveryAddress
228
     *
229
     * @return Customer
230
     */
231
    public function withDeliveryAddress(CustomerDeliveryAddress $deliveryAddress)
232
    {
233
        $new = clone $this;
234
        $new->deliveryAddress = $deliveryAddress;
235
236
        return $new;
237
    }
238
239
    /**
240
     * @return string
241
     */
242
    public function getCompanyType()
243
    {
244
        return $this->companyType;
245
    }
246
247
    /**
248
     * @param string $companyType
249
     *
250
     * @return Customer
251
     */
252
    public function withCompanyType(string $companyType)
253
    {
254
        $new = clone $this;
255
        $new->companyType = $companyType;
256
257
        return $new;
258
    }
259
260
    /**
261
     * @return \DateTime
262
     */
263
    public function getCreatedAt(): \DateTime
264
    {
265
        return $this->createdAt;
266
    }
267
268
    /**
269
     * @return \DateTime
270
     */
271
    public function getUpdatedAt(): \DateTime
272
    {
273
        return $this->updatedAt;
274
    }
275
276
    /**
277
     * @param \DateTime $updatedAt
278
     */
279
    public function setUpdatedAt(\DateTime $updatedAt)
280
    {
281
        $this->updatedAt = $updatedAt;
282
    }
283
284 4
    public static function createFromArray(array $data): Customer
285
    {
286 4
        $customer = new self();
287 4
        if (array_key_exists('data', $data)) {
288
            $customerArray = $data['data'];
289
            $contactArray = $customerArray['contact'];
290
            $addressArray = $customerArray['address'];
291
            $deliveryAddressArray = $customerArray['delivery_address'];
292
293
            $contact = CustomerContact::createFromArray($contactArray);
294
            $address = CustomerBillingAddress::createFromArray($addressArray);
295
            $deliveryAddress = CustomerDeliveryAddress::createFromArray($deliveryAddressArray);
296
            $customer->contact = $contact;
297
            $customer->address = $address;
298
        } else {
299 4
            $customerArray = $data;
300 4
            $deliveryAddressArray = $customerArray['address'] ?? null;
301 4
            $deliveryAddress = CustomerDeliveryAddress::createFromArray(['name' => $customerArray['name'] ?? null, 'street_address' => $deliveryAddressArray['street_address'], 'careof' => $deliveryAddressArray['careof'], 'zipcode' => $deliveryAddressArray['zipcode'], 'city' => $deliveryAddressArray['city'], 'country' => $deliveryAddressArray['country']]) ?? null;
302 4
            $contact = CustomerContact::createFromArray(['name' => $customerArray['name'], 'email' => $customerArray['email'], 'phone' => $customerArray['phone'] ?? null]) ?? null;
303
        }
304 4
        $customer->deliveryAddress = $deliveryAddress ?? null;
305 4
        $customer->contact = $contact ?? null;
306 4
        $customer->customerNo = $customerArray['customer_no'] ?? null;
307 4
        $customer->name = $customerArray['name'] ?? null;
308 4
        $customer->notes = $customerArray['notes'] ?? null;
309 4
        $customer->orgNo = $customerArray['org_no'] ?? null;
310 4
        $customer->vatNo = $customerArray['vat_no'] ?? null;
311
312 4
        $customer->createdAt = $customerArray['created_at'] ?? null;
313 4
        $customer->updatedAt = $customerArray['updated_at'] ?? null;
314 4
        $customer->companyType = $customerArray['company_type'] ?? null;
315
316 4
        return $customer;
317
    }
318
319 2
    public function toArray()
320
    {
321 2
        $data = [];
322 2
        if ($this->customerNo !== null) {
323 2
            $data['customer_no'] = $this->customerNo;
324
        }
325 2
        if ($this->name !== null) {
326
            $data['name'] = $this->name;
327
        }
328 2
        if ($this->notes !== null) {
329
            $data['notes'] = $this->notes;
330
        }
331 2
        if ($this->orgNo !== null) {
332
            $data['org_no'] = $this->orgNo;
333
        }
334 2
        if ($this->vatNo !== null) {
335
            $data['vat_no'] = $this->vatNo ?? null;
336
        }
337 2
        if ($this->contact !== null) {
338
            $data['contact'] = $this->contact->toArray();
339
        }
340 2
        if ($this->address !== null) {
341
            $data['address'] = $this->address->toArray();
342
        }
343 2
        if ($this->deliveryAddress !== null) {
344
            $data['delivery_address'] = $this->deliveryAddress->toArray();
345
        }
346
347 2
        return $data;
348
    }
349
}
350