InvoiceAddress::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Setting;
6
7
use Billogram\Model\BaseAddress;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class InvoiceAddress extends BaseAddress
13
{
14
    /**
15
     * @var string
16
     */
17
    private $email;
18
19
    /**
20
     * @return string
21
     */
22
    public function getEmail(): string
23
    {
24
        return $this->email;
25
    }
26
27
    /**
28
     * @param string $email
29
     *
30
     * @return InvoiceAddress
31
     */
32
    public function withEmail(string $email)
33
    {
34
        $new = clone $this;
35
        $new->email = $email;
36
37
        return $new;
38
    }
39
40
    /**
41
     * Create an API response object from the HTTP response from the API server.
42
     *
43
     * @param array $data
44
     *
45
     * @return self
46
     */
47 2
    public static function createFromArray(array $data)
48
    {
49 2
        $invoiceAddress = new self();
50 2
        $invoiceAddress->careOf = $data['careof'] ?? null;
51 2
        $invoiceAddress->streetAddress = $data['street_address'] ?? null;
52 2
        $invoiceAddress->zipCode = $data['zipcode'] ?? null;
53 2
        $invoiceAddress->city = $data['city'] ?? null;
54 2
        $invoiceAddress->country = $data['country'] ?? null;
55 2
        $invoiceAddress->email = $data['email'] ?? null;
56
57 2
        return $invoiceAddress;
58
    }
59
60
    /**
61
     * @return array
62
     */
63 1
    public function toArray()
64
    {
65 1
        $data = parent::toArray();
66 1
        if (null !== $this->email) {
67 1
            $data['email'] = $this->email;
68
        }
69
70 1
        return $data;
71
    }
72
}
73