Seller   A
last analyzed

Complexity

Total Complexity 34

Size/Duplication

Total Lines 350
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 72
c 1
b 0
f 0
dl 0
loc 350
rs 9.68
wmc 34

28 Methods

Rating   Name   Duplication   Size   Complexity  
A setEmail() 0 4 1
A cpf_cnpj() 0 8 2
A setBirthdate() 0 4 1
A setOwner() 0 4 1
A setLogin() 0 4 1
A getOwner() 0 3 1
A schema() 0 18 1
A getBirthdate() 0 3 1
A setCpfCnpj() 0 4 1
A setDescription() 0 4 1
A setName() 0 4 1
A setBank() 0 4 1
A phone() 0 8 2
A getPhone() 0 3 1
A getName() 0 3 1
A setAddress() 0 4 1
A getBank() 0 3 1
A getDescription() 0 3 1
A birthdate() 0 10 4
A setPhone() 0 4 1
A getEmail() 0 3 1
A getCpfCnpj() 0 3 1
A __construct() 0 3 1
A getPassword() 0 3 1
A email() 0 8 2
A getAddress() 0 3 1
A setPassword() 0 4 1
A getLogin() 0 3 1
1
<?php
2
3
namespace Ipag\Sdk\Model;
4
5
use Ipag\Sdk\Model\Schema\Mutator;
6
use Ipag\Sdk\Model\Schema\Schema;
7
use Ipag\Sdk\Model\Schema\SchemaBuilder;
8
use Kubinyete\Assertation\Assert;
9
10
/**
11
 * Seller Class
12
 *
13
 * Classe responsável por representar o recurso Seller.
14
 *
15
 */
16
final class Seller extends Model
17
{
18
19
    /**
20
     *  @param array $data
21
     *  array de dados do recurso `Seller`
22
     *
23
     *  + [`'login'`] string (opcional).
24
     *  + [`'password'`] string (opcional).
25
     *  + [`'name'`] string (opcional).
26
     *  + [`'cpf_cnpj'`] string (opcional).
27
     *  + [`'email'`] string (opcional).
28
     *  + [`'phone'`] string (opcional).
29
     *  + [`'birthdate'`] string (opcional) {`Formato: Y-m-d`}.
30
     *  + [`'description'`] string (opcional).
31
     *
32
     *  + [`'address'`] array (opcional) dos dados do Address.
33
     *  + &emsp; [`'street'`] string (opcional).
34
     *  + &emsp; [`'number'`] string (opcional).
35
     *  + &emsp; [`'district'`] string (opcional).
36
     *  + &emsp; [`'city'`] string (opcional).
37
     *  + &emsp; [`'state'`] string (opcional).
38
     *  + &emsp; [`'zipcode'`] string (opcional).
39
     *
40
     *  + [`'owner'`] array (opcional) dos dados do Owner.
41
     *  + &emsp; [`'name'`] string (opcional).
42
     *  + &emsp; [`'email'`] string (opcional).
43
     *  + &emsp; [`'cpf'`] string (opcional).
44
     *  + &emsp; [`'phone'`] string (opcional)
45
     *  + &emsp; [`'birthdate'`] string (opcional)
46
     *
47
     *  + [`'bank'`] array (opcional) dos dados do Bank.
48
     *  + &emsp; [`'code'`] string (opcional).
49
     *  + &emsp; [`'agency'`] string (opcional).
50
     *  + &emsp; [`'account'`] string (opcional).
51
     *  + &emsp; [`'type'`] enum {`'checkings'` | `'savings'`} (opcional).
52
     *  + &emsp; [`'external_id'`] string (opcional)
53
     */
54
    public function __construct(?array $data = [])
55
    {
56
        parent::__construct($data);
57
    }
58
59
    public function schema(SchemaBuilder $schema): Schema
60
    {
61
        $schema->string('login')->nullable();
62
        $schema->string('password')->nullable();
63
        $schema->string('name')->nullable();
64
        $schema->string('cpf_cnpj')->nullable();
65
        $schema->string('email')->nullable();
66
        $schema->string('phone')->nullable();
67
        $schema->string('birthdate')->nullable();
68
        $schema->string('description')->nullable();
69
70
        $schema->has('address', Address::class)->nullable();
71
72
        $schema->has('owner', Owner::class)->nullable();
73
74
        $schema->has('bank', Bank::class)->nullable();
75
76
        return $schema->build();
77
    }
78
79
    protected function cpf_cnpj(): Mutator
80
    {
81
        return new Mutator(
82
            null,
83
            fn($value, $ctx) =>
84
            is_null($value) ?
85
            $value :
86
            Assert::value($value)->asCpf(false)->or()->asCnpj(false)->get() ?? $ctx->raise('inválido')
87
        );
88
    }
89
90
    protected function email(): Mutator
91
    {
92
        return new Mutator(
93
            null,
94
            fn($value, $ctx) =>
95
            is_null($value) ?
96
            $value :
97
            Assert::value($value)->email()->get() ?? $ctx->raise('inválido')
98
        );
99
    }
100
101
    protected function phone(): Mutator
102
    {
103
        return new Mutator(
104
            null,
105
            fn($value, $ctx) =>
106
            is_null($value) ?
107
            $value :
108
            Assert::value($value)->asDigits()->lbetween(10, 11)->get() ?? $ctx->raise('inválido')
109
        );
110
    }
111
112
    protected function birthdate(): Mutator
113
    {
114
        return new Mutator(
115
            null,
116
            function ($value, $ctx) {
117
                $d = \DateTime::createFromFormat('Y-m-d', $value);
118
119
                return is_null($value) ||
120
                    ($d && $d->format('Y-m-d') === $value) ?
121
                    $value : $ctx->raise('inválido');
122
            }
123
        );
124
    }
125
126
    /**
127
     * Retorna o valor da propriedade `login`.
128
     *
129
     * @return string|null
130
     */
131
    public function getLogin(): ?string
132
    {
133
        return $this->get('login');
134
    }
135
136
    /**
137
     * Seta o valor da propriedade `login`.
138
     *
139
     * @param string|null $login
140
     * @return self
141
     */
142
    public function setLogin(?string $login = null): self
143
    {
144
        $this->set('login', $login);
145
        return $this;
146
    }
147
148
    /**
149
     * Retorna o valor da propriedade `password`.
150
     *
151
     * @return string|null
152
     */
153
    public function getPassword(): ?string
154
    {
155
        return $this->get('password');
156
    }
157
158
    /**
159
     * Seta o valor da propriedade `password`.
160
     *
161
     * @param string|null $password
162
     * @return self
163
     */
164
    public function setPassword(?string $password = null): self
165
    {
166
        $this->set('password', $password);
167
        return $this;
168
    }
169
170
    /**
171
     * Retorna o valor da propriedade `name`.
172
     *
173
     * @return string|null
174
     */
175
    public function getName(): ?string
176
    {
177
        return $this->get('name');
178
    }
179
180
    /**
181
     * Seta o valor da propriedade `name`.
182
     *
183
     * @param string|null $name
184
     * @return self
185
     */
186
    public function setName(?string $name = null): self
187
    {
188
        $this->set('name', $name);
189
        return $this;
190
    }
191
192
    /**
193
     * Retorna o valor da propriedade `cpf_cnpj`.
194
     *
195
     * @return string|null
196
     */
197
    public function getCpfCnpj(): ?string
198
    {
199
        return $this->get('cpf_cnpj');
200
    }
201
202
    /**
203
     * Seta o valor da propriedade `cpf_cnpj`.
204
     *
205
     * @param string|null $cpf_cnpj
206
     * @return self
207
     */
208
    public function setCpfCnpj(?string $cpf_cnpj = null): self
209
    {
210
        $this->set('cpf_cnpj', $cpf_cnpj);
211
        return $this;
212
    }
213
214
    /**
215
     * Retorna o valor da propriedade `email`.
216
     *
217
     * @return string|null
218
     */
219
    public function getEmail(): ?string
220
    {
221
        return $this->get('email');
222
    }
223
224
    /**
225
     * Seta o valor da propriedade `email`.
226
     *
227
     * @param string|null $email
228
     * @return self
229
     */
230
    public function setEmail(?string $email = null): self
231
    {
232
        $this->set('email', $email);
233
        return $this;
234
    }
235
236
    /**
237
     * Retorna o valor da propriedade `phone`.
238
     *
239
     * @return string|null
240
     */
241
    public function getPhone(): ?string
242
    {
243
        return $this->get('phone');
244
    }
245
246
    /**
247
     * Seta o valor da propriedade `phone`.
248
     *
249
     * @param string|null $phone
250
     * @return self
251
     */
252
    public function setPhone(?string $phone = null): self
253
    {
254
        $this->set('phone', $phone);
255
        return $this;
256
    }
257
258
    /**
259
     * Retorna o valor da propriedade `birthdate`.
260
     *
261
     * @return string|null
262
     */
263
    public function getBirthdate(): ?string
264
    {
265
        return $this->get('birthdate');
266
    }
267
268
    /**
269
     * Seta o valor da propriedade `birthdate`.
270
     *
271
     * @param string|null $birthdate
272
     * @return self
273
     */
274
    public function setBirthdate(?string $birthdate = null): self
275
    {
276
        $this->set('birthdate', $birthdate);
277
        return $this;
278
    }
279
280
    /**
281
     * Retorna o valor da propriedade `description`.
282
     *
283
     * @return string|null
284
     */
285
    public function getDescription(): ?string
286
    {
287
        return $this->get('description');
288
    }
289
290
    /**
291
     * Seta o valor da propriedade `description`.
292
     *
293
     * @param string|null $description
294
     * @return self
295
     */
296
    public function setDescription(?string $description = null): self
297
    {
298
        $this->set('description', $description);
299
        return $this;
300
    }
301
302
    /**
303
     * Retorna o objeto `Address` referente ao `Seller`.
304
     *
305
     * @return Address|null
306
     */
307
    public function getAddress(): ?Address
308
    {
309
        return $this->get('address');
310
    }
311
312
    /**
313
     * Seta o objeto `Address` referente ao `Seller`.
314
     *
315
     * @param Address|null $address
316
     * @return self
317
     */
318
    public function setAddress(?Address $address = null): self
319
    {
320
        $this->set('address', $address);
321
        return $this;
322
    }
323
324
    /**
325
     * Retorna o objeto `Owner` referente ao `Seller`.
326
     *
327
     * @return Owner|null
328
     */
329
    public function getOwner(): ?Owner
330
    {
331
        return $this->get('owner');
332
    }
333
334
    /**
335
     * Seta o objeto `Owner` referente ao `Seller`.
336
     *
337
     * @param Owner|null $owner
338
     * @return self
339
     */
340
    public function setOwner(?Owner $owner = null): self
341
    {
342
        $this->set('owner', $owner);
343
        return $this;
344
    }
345
346
    /**
347
     * Retorna o objeto `Bank` referente ao `Seller`.
348
     *
349
     * @return Bank|null
350
     */
351
    public function getBank(): ?Bank
352
    {
353
        return $this->get('bank');
354
    }
355
356
    /**
357
     * Seta o objeto `Bank` referente ao `Seller`.
358
     *
359
     * @param Bank|null $bank
360
     * @return self
361
     */
362
    public function setBank(?Bank $bank = null): self
363
    {
364
        $this->set('bank', $bank);
365
        return $this;
366
    }
367
368
}