Passed
Pull Request — master (#10)
by Lucas
02:20
created

Address::country()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Ipag\Sdk\Model;
4
5
use Ipag\Sdk\Util\StateUtil;
6
use Ipag\Sdk\Model\Schema\Schema;
7
use Ipag\Sdk\Model\Schema\Mutator;
8
use Ipag\Sdk\Model\Schema\SchemaBuilder;
9
10
/**
11
 * Address Class
12
 *
13
 * Classe responsável por representar o recurso Address.
14
 */
15
final class Address extends Model
16
{
17
    /**
18
     *  @param array $data
19
     *  array de dados do Address.
20
     *
21
     *  + [`'street'`] string (opcional).
22
     *  + [`'number'`] string (opcional).
23
     *  + [`'district'`] string (opcional).
24
     *  + [`'complement'`] string (opcional).
25
     *  + [`'city'`] string (opcional).
26
     *  + [`'state'`] string (opcional).
27
     *  + [`'zipcode'`] string (opcional).
28
     *  + [`'country'`] string (opcional).
29
     */
30
    public function __construct(?array $data = [])
31
    {
32
        parent::__construct($data);
33
    }
34
35
    protected function schema(SchemaBuilder $schema): Schema
36
    {
37
        $schema->string('street')->nullable();
38
        $schema->string('number')->nullable();
39
        $schema->string('district')->nullable();
40
        $schema->string('complement')->nullable();
41
        $schema->string('city')->nullable();
42
        $schema->string('state')->nullable();
43
        $schema->string('zipcode')->nullable();
44
        $schema->string('country')->nullable();
45
46
        return $schema->build();
47
    }
48
49
    public function street(): Mutator
50
    {
51
        return new Mutator(
52
            null,
53
            fn ($value) => strval($value)
54
        );
55
    }
56
57
    /**
58
     * Retorna o valor da propriedade street.
59
     *
60
     * @return string|null
61
     */
62
    public function getStreet(): ?string
63
    {
64
        return $this->get('street');
65
    }
66
67
    /**
68
     * Seta o valor da propriedade street.
69
     *
70
     * @param string|null $street
71
     * @return self
72
     */
73
    public function setStreet(?string $street): self
74
    {
75
        $this->set('street', $street);
76
        return $this;
77
    }
78
79
    public function number(): Mutator
80
    {
81
        return new Mutator(
82
            null,
83
            fn ($value) => strval($value)
84
        );
85
    }
86
87
    /**
88
     * Retorna o valor da propriedade number.
89
     *
90
     * @return string|null
91
     */
92
    public function getNumber(): ?string
93
    {
94
        return $this->get('number');
95
    }
96
97
    /**
98
     * Seta o valor da propriedade number.
99
     *
100
     * @param string|null $number
101
     * @return self
102
     */
103
    public function setNumber(?string $number): self
104
    {
105
        $this->set('number', $number);
106
        return $this;
107
    }
108
109
    public function district(): Mutator
110
    {
111
        return new Mutator(null, fn ($value) => strval($value));
112
    }
113
114
    /**
115
     * Retorna o valor da propriedade district.
116
     *
117
     * @return string|null
118
     */
119
    public function getDistrict(): ?string
120
    {
121
        return $this->get('district');
122
    }
123
124
    /**
125
     * Seta o valor da propriedade district.
126
     *
127
     * @param string|null $district
128
     * @return self
129
     */
130
    public function setDistrict(?string $district): self
131
    {
132
        $this->set('district', $district);
133
        return $this;
134
    }
135
    public function complement(): Mutator
136
    {
137
        return new Mutator(null, fn ($value) => strval($value));
138
    }
139
140
    /**
141
     * Retorna o valor da propriedade complement.
142
     *
143
     * @return string|null
144
     */
145
    public function getComplement(): ?string
146
    {
147
        return $this->get('complement');
148
    }
149
150
    /**
151
     * Seta o valor da propriedade complement.
152
     *
153
     * @param string|null $complement
154
     * @return self
155
     */
156
    public function setComplement(?string $complement): self
157
    {
158
        $this->set('complement', $complement);
159
        return $this;
160
    }
161
    public function city(): Mutator
162
    {
163
        return new Mutator(null, fn ($value) => strval($value));
164
    }
165
166
    /**
167
     * Retorna o valor da propriedade city.
168
     *
169
     * @return string|null
170
     */
171
    public function getCity(): ?string
172
    {
173
        return $this->get('city');
174
    }
175
176
    /**
177
     * Seta o valor da propriedade city.
178
     *
179
     * @param string|null $city
180
     * @return self
181
     */
182
    public function setCity(?string $city): self
183
    {
184
        $this->set('city', $city);
185
        return $this;
186
    }
187
    public function state(): Mutator
188
    {
189
        return new Mutator(null, fn ($value) => !$value ? null : StateUtil::transformState($value));
190
    }
191
192
    /**
193
     * Retorna o valor da propriedade state.
194
     *
195
     * @return string|null
196
     */
197
    public function getState(): ?string
198
    {
199
        return $this->get('state');
200
    }
201
202
    /**
203
     * Seta o valor da propriedade state.
204
     *
205
     * @param string|null $state
206
     * @return self
207
     */
208
    public function setState(?string $state): self
209
    {
210
        $this->set('state', $state);
211
        return $this;
212
    }
213
    public function zipcode(): Mutator
214
    {
215
        return new Mutator(null, fn ($value) => strval(preg_replace('/\D/', '', $value)));
216
    }
217
218
    /**
219
     * Retorna o valor da propriedade zipcode.
220
     *
221
     * @return string|null
222
     */
223
    public function getZipcode(): ?string
224
    {
225
        return $this->get('zipcode');
226
    }
227
228
    /**
229
     * Seta o valor da propriedade zipcode.
230
     *
231
     * @param string|null $zipcode
232
     * @return self
233
     */
234
    public function setZipcode(?string $zipcode): self
235
    {
236
        $this->set('zipcode', $zipcode);
237
        return $this;
238
    }
239
240
    public function country(): Mutator
241
    {
242
        return new Mutator(null, fn ($value, $ctx) => is_null($value) ? null : (strlen($value) !== 2 ? $ctx->raise('inválido') : strval($value)));
243
    }
244
245
    /**
246
     * Retorna o valor da propriedade country.
247
     *
248
     * @return string|null
249
     */
250
    public function getCountry(): ?string
251
    {
252
        return $this->get('country');
253
    }
254
255
    /**
256
     * Seta o valor da propriedade country.
257
     *
258
     * @param string|null $country
259
     * @return self
260
     */
261
    public function setCountry(?string $country): self
262
    {
263
        $this->set('country', $country);
264
        return $this;
265
    }
266
}
267