Passed
Push — master ( bb72b6...3e58cd )
by Manuel
02:16
created

Address::setCity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sprain\SwissQrBill\DataGroups;
4
5
use Sprain\SwissQrBill\DataGroups\Interfaces\QrCodeData;
6
use Sprain\SwissQrBill\Validator\Interfaces\Validatable;
7
use Sprain\SwissQrBill\Validator\ValidatorTrait;
8
use Symfony\Component\Validator\Constraints as Assert;
9
use Symfony\Component\Validator\Mapping\ClassMetadata;
10
11
class Address implements QrCodeData, Validatable
12
{
13
    use ValidatorTrait;
14
15
    /**
16
     * Name or company
17
     *
18
     * For creditors: Always matches the account holder.
19
     *
20
     * @var string
21
     */
22
    private $name;
23
24
    /**
25
     * Street / P.O. box of the creditor.
26
     *
27
     * May not include building or house number.
28
     *
29
     * @var string
30
     */
31
    private $street;
32
33
    /**
34
     * House number of the creditor
35
     *
36
     * @var string
37
     */
38
    private $houseNumber;
39
40
    /**
41
     * Postal code without county code
42
     *
43
     * @var string
44
     */
45
    private $postalCode;
46
47
    /**
48
     * City
49
     *
50
     * @var string
51
     */
52
    private $city;
53
54
    /**
55
     * Country (ISO 3166-1 alpha-2)
56
     *
57
     * @var string
58
     */
59
    private $country;
60
61
62
    public function getName(): ?string
63
    {
64
        return $this->name;
65
    }
66
67
    public function setName(string $name) : self
68
    {
69
        $this->name = $name;
70
71
        return $this;
72
    }
73
74
    public function getStreet(): ?string
75
    {
76
        return $this->street;
77
    }
78
79
    public function setStreet(string $street = null) : self
80
    {
81
        $this->street = $street;
82
83
        return $this;
84
    }
85
86
    public function getHouseNumber(): ?string
87
    {
88
        return $this->houseNumber;
89
    }
90
91
    public function setHouseNumber(string $houseNumber = null) : self
92
    {
93
        $this->houseNumber = $houseNumber;
94
95
        return $this;
96
    }
97
98
    public function getPostalCode(): ?string
99
    {
100
        return $this->postalCode;
101
    }
102
103
    public function setPostalCode(string $postalCode) : self
104
    {
105
        $this->postalCode = $postalCode;
106
107
        return $this;
108
    }
109
110
    public function getCity(): ?string
111
    {
112
        return $this->city;
113
    }
114
115
    public function setCity(string $city) : self
116
    {
117
        $this->city = $city;
118
119
        return $this;
120
    }
121
122
    public function getCountry(): ?string
123
    {
124
        return $this->country;
125
    }
126
127
    public function setCountry(string $country) : self
128
    {
129
        $this->country = strtoupper($country);
130
131
        return $this;
132
    }
133
134
    public function getQrCodeData() : array
135
    {
136
        return [
137
            $this->getName(),
138
            $this->getStreet(),
139
            $this->getHouseNumber(),
140
            $this->getPostalCode(),
141
            $this->getCity(),
142
            $this->getCountry()
143
        ];
144
    }
145
146
    public static function loadValidatorMetadata(ClassMetadata $metadata)
147
    {
148
        $metadata->addPropertyConstraints('name', [
149
            new Assert\NotBlank(),
150
            new Assert\Length([
151
                'max' => 70
152
            ])
153
        ]);
154
155
        $metadata->addPropertyConstraints('street', [
156
            new Assert\Length([
157
                'max' => 70
158
            ])
159
        ]);
160
161
        $metadata->addPropertyConstraints('houseNumber', [
162
            new Assert\Length([
163
                'max' => 16
164
            ])
165
        ]);
166
167
        $metadata->addPropertyConstraints('postalCode', [
168
            new Assert\NotBlank(),
169
            new Assert\Length([
170
                'max' => 16
171
            ])
172
        ]);
173
174
        $metadata->addPropertyConstraints('city', [
175
            new Assert\NotBlank(),
176
            new Assert\Length([
177
                'max' => 35
178
            ])
179
        ]);
180
181
        $metadata->addPropertyConstraints('country', [
182
            new Assert\NotBlank(),
183
            new Assert\Country()
184
        ]);
185
    }
186
}