Completed
Branch develop (a0a623)
by Romain
02:33
created

Address::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: rmo
5
 * Date: 13/11/2016
6
 * Time: 01:58
7
 */
8
9
namespace Kerox\Messenger\Message\Attachment\Template\Receipt;
10
11
12
class Address implements \JsonSerializable
13
{
14
15
    /**
16
     * @var string
17
     */
18
    protected $street;
19
20
    /**
21
     * @var null|string
22
     */
23
    protected $additionalStreet;
24
25
    /**
26
     * @var string
27
     */
28
    protected $city;
29
30
    /**
31
     * @var string
32
     */
33
    protected $postalCode;
34
35
    /**
36
     * @var string
37
     */
38
    protected $state;
39
40
    /**
41
     * @var string
42
     */
43
    protected $country;
44
45
    /**
46
     * Address constructor.
47
     *
48
     * @param string $street
49
     * @param string $city
50
     * @param string $postalCode
51
     * @param string $state
52
     * @param string $country
53
     */
54
    public function __construct(string $street,
55
                                string $city,
56
                                string $postalCode,
57
                                string $state,
58
                                string $country
59
    ) {
60
        $this->street = $street;
61
        $this->city = $city;
62
        $this->postalCode = $postalCode;
63
        $this->state = $state;
64
        $this->country = $country;
65
    }
66
67
    /**
68
     * @param string $additionalStreet
69
     * @return Address
70
     */
71
    public function setAdditionalStreet(string $additionalStreet): Address
72
    {
73
        $this->additionalStreet = $additionalStreet;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function jsonSerialize(): array
82
    {
83
        $json = [
84
            'street_1' => $this->street,
85
            'street_2' => $this->additionalStreet,
86
            'city' => $this->city,
87
            'postal_code' => $this->postalCode,
88
            'state' => $this->state,
89
            'country' => $this->country,
90
        ];
91
92
        return array_filter($json);
93
    }
94
}
95