1 | <?php |
||
2 | |||
3 | namespace Ipag\Classes; |
||
4 | |||
5 | use Ipag\Classes\Contracts\Emptiable; |
||
6 | use Ipag\Classes\Contracts\ObjectSerializable; |
||
7 | use Ipag\Classes\Traits\EmptiableTrait; |
||
8 | |||
9 | final class Address extends BaseResource implements Emptiable, ObjectSerializable |
||
10 | { |
||
11 | use EmptiableTrait; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $street; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $number; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $complement; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $neighborhood; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $city; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $state; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $country; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $zipCode; |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getStreet() |
||
57 | { |
||
58 | return $this->street; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getNumber() |
||
65 | { |
||
66 | return $this->number; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getComplement() |
||
73 | { |
||
74 | return $this->complement; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getNeighborhood() |
||
81 | { |
||
82 | return $this->neighborhood; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getCity() |
||
89 | { |
||
90 | return $this->city; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getState() |
||
97 | { |
||
98 | return $this->state; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getCountry() |
||
105 | { |
||
106 | if (is_null($this->country)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
107 | $this->setCountry('BR'); |
||
108 | } |
||
109 | |||
110 | return $this->country; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getZipCode() |
||
117 | { |
||
118 | return $this->zipCode; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @param string $street |
||
123 | */ |
||
124 | public function setStreet($street) |
||
125 | { |
||
126 | $this->street = substr((string) $street, 0, 100); |
||
127 | |||
128 | return $this; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @param string $number |
||
133 | */ |
||
134 | public function setNumber($number) |
||
135 | { |
||
136 | $this->number = substr((string) $number, 0, 15); |
||
137 | |||
138 | return $this; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @param string $complement |
||
143 | */ |
||
144 | public function setComplement($complement) |
||
145 | { |
||
146 | $this->complement = substr((string) $complement, 0, 255); |
||
147 | |||
148 | return $this; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @param string $neighborhood |
||
153 | */ |
||
154 | public function setNeighborhood($neighborhood) |
||
155 | { |
||
156 | $this->neighborhood = substr((string) $neighborhood, 0, 40); |
||
157 | |||
158 | return $this; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @param string $city |
||
163 | */ |
||
164 | public function setCity($city) |
||
165 | { |
||
166 | $this->city = substr((string) $city, 0, 40); |
||
167 | |||
168 | return $this; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @param string $state |
||
173 | */ |
||
174 | public function setState($state) |
||
175 | { |
||
176 | $this->state = substr((string) $state, 0, 2); |
||
177 | |||
178 | return $this; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @param string $country |
||
183 | */ |
||
184 | public function setCountry($country) |
||
185 | { |
||
186 | $this->country = substr($country, 0, 3); |
||
187 | |||
188 | return $this; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param string $zipCode |
||
193 | */ |
||
194 | public function setZipCode($zipCode) |
||
195 | { |
||
196 | $this->zipCode = substr($this->getNumberUtil()->getOnlyNumbers($zipCode), 0, 8); |
||
197 | |||
198 | return $this; |
||
199 | } |
||
200 | |||
201 | public function serialize() |
||
202 | { |
||
203 | if ($this->isEmpty()) { |
||
204 | return []; |
||
205 | } |
||
206 | |||
207 | return [ |
||
208 | 'endereco' => urlencode((string) $this->getStreet()), |
||
209 | 'numero_endereco' => urlencode((string) $this->getNumber()), |
||
210 | 'complemento' => urlencode((string) $this->getComplement()), |
||
211 | 'bairro' => urlencode((string) $this->getNeighborhood()), |
||
212 | 'cidade' => urlencode((string) $this->getCity()), |
||
213 | 'estado' => urlencode((string) $this->getState()), |
||
214 | 'pais' => urlencode((string) $this->getCountry()), |
||
215 | 'cep' => urlencode((string) $this->getZipCode()), |
||
216 | ]; |
||
217 | } |
||
218 | } |
||
219 |