Establishment::setBank()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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
 * Establishment Class
12
 *
13
 * Classe responsável por representar o recurso Establishment.
14
 */
15
class Establishment extends Model
16
{
17
    /**
18
     *  @param array $data
19
     *  array de dados do Establishment.
20
     *
21
     *  + [`'name'`] string (opcional)
22
     *  + [`'email'`] string (opcional)
23
     *  + [`'login'`] string (opcional)
24
     *  + [`'password'`] string (opcional)
25
     *  + [`'document'`] string (opcional)
26
     *  + [`'phone'`] string (opcional)
27
     *  + [`'address'`] array (opcional) dos dados do Address.
28
     *  + &emsp; [`'street'`] string (opcional).
29
     *  + &emsp; [`'number'`] string (opcional).
30
     *  + &emsp; [`'district'`] string (opcional).
31
     *  + &emsp; [`'city'`] string (opcional).
32
     *  + &emsp; [`'state'`] string (opcional).
33
     *  + &emsp; [`'zipcode'`] string (opcional).
34
     *  + [`'owner'`] array (opcional) dos dados do Owner.
35
     *  + &emsp; [`'name'`] string (opcional).
36
     *  + &emsp; [`'email'`] string (opcional).
37
     *  + &emsp; [`'cpf'`] string (opcional).
38
     *  + &emsp; [`'phone'`] string (opcional).
39
     *  + [`'bank'`] array '`] array (opcional) dos dados do Bank.
40
     *  + &emsp; [`'code'`] string (opcional).
41
     *  + &emsp; [`'agency'`] string (opcional).
42
     *  + &emsp; [`'account'`] string (opcional).
43
     *  + &emsp; [`'type'`] enum {`'checkings'` | `'savings'`} (opcional).
44
     *  + &emsp; [`'external_id'`] string (opcional).
45
     */
46
    public function __construct(?array $data = [])
47
    {
48
        parent::__construct($data);
49
    }
50
51
    protected function schema(SchemaBuilder $schema): Schema
52
    {
53
54
        $schema->string('name')->nullable();
55
        $schema->string('email')->nullable();
56
        $schema->string('login')->nullable();
57
        $schema->string('password')->nullable()->isHidden();
58
        $schema->string('document')->nullable();
59
        $schema->string('phone')->nullable();
60
61
        $schema->has('address', Address::class)->nullable();
62
        $schema->has('owner', Owner::class)->nullable();
63
        $schema->has('bank', Bank::class)->nullable();
64
65
        return $schema->build();
66
    }
67
68
    protected function email(): Mutator
69
    {
70
        return new Mutator(
71
            null,
72
            fn($value, $ctx) =>
73
            is_null($value) ?
74
            $value :
75
            Assert::value($value)->email()->get() ?? $ctx->raise('inválido')
76
        );
77
    }
78
79
    protected function document(): Mutator
80
    {
81
        return new Mutator(
82
            null,
83
            fn($value, $ctx) =>
84
            is_null($value) ?
85
            $value :
86
            Assert::value($value)->asCpf(false)->get() ?? $ctx->raise('inválido')
87
        );
88
    }
89
90
    protected function phone(): Mutator
91
    {
92
        return new Mutator(
93
            null,
94
            fn($value, $ctx) =>
95
            is_null($value) ?
96
            $value :
97
            Assert::value($value)->asDigits()->lbetween(10, 11)->get() ?? $ctx->raise('inválido')
98
        );
99
    }
100
101
    /**
102
     * Retorna o valor da propriedade name
103
     *
104
     * @return string|null
105
     */
106
    public function getName(): ?string
107
    {
108
        return $this->get('name');
109
    }
110
111
    /**
112
     * Seta o valor da propriedade name
113
     *
114
     * @param string|null $name
115
     * @return self
116
     */
117
    public function setName(?string $name = null): self
118
    {
119
        $this->set('name', $name);
120
        return $this;
121
    }
122
123
    /**
124
     * Retorna o valor da propriedade email
125
     *
126
     * @return string|null
127
     */
128
    public function getEmail(): ?string
129
    {
130
        return $this->get('email');
131
    }
132
133
    /**
134
     * Seta o valor da propriedade email
135
     *
136
     * @param string|null $email
137
     * @return self
138
     */
139
    public function setEmail(?string $email = null): self
140
    {
141
        $this->set('email', $email);
142
        return $this;
143
    }
144
145
    /**
146
     * Retorna o valor da propriedade login
147
     *
148
     * @return string|null
149
     */
150
    public function getLogin(): ?string
151
    {
152
        return $this->get('login');
153
    }
154
155
    /**
156
     * Seta o valor da propriedade login
157
     *
158
     * @param string|null $login
159
     * @return self
160
     */
161
    public function setLogin(?string $login = null): self
162
    {
163
        $this->set('login', $login);
164
        return $this;
165
    }
166
167
    /**
168
     * Retorna o valor da propriedade password
169
     *
170
     * @return string|null
171
     */
172
    public function getPassword(): ?string
173
    {
174
        return $this->get('password');
175
    }
176
177
    /**
178
     * Seta o valor da propriedade password
179
     *
180
     * @param string|null $password
181
     * @return self
182
     */
183
    public function setPassword(?string $password = null): self
184
    {
185
        $this->set('password', $password);
186
        return $this;
187
    }
188
189
    /**
190
     * Retorna o valor da propriedade document
191
     *
192
     * @return string|null
193
     */
194
    public function getDocument(): ?string
195
    {
196
        return $this->get('document');
197
    }
198
199
    /**
200
     * Seta o valor da propriedade document
201
     *
202
     * @param string|null $document
203
     * @return self
204
     */
205
    public function setDocument(?string $document = null): self
206
    {
207
        $this->set('document', $document);
208
        return $this;
209
    }
210
211
    /**
212
     * Retorna o valor da propriedade phone
213
     *
214
     * @return string|null
215
     */
216
    public function getPhone(): ?string
217
    {
218
        return $this->get('phone');
219
    }
220
221
    /**
222
     * Seta o valor da propriedade phone
223
     *
224
     * @param string|null $phone
225
     * @return self
226
     */
227
    public function setPhone(?string $phone = null): self
228
    {
229
        $this->set('phone', $phone);
230
        return $this;
231
    }
232
233
    /**
234
     * Retorna o valor da propriedade address
235
     *
236
     * @return Address|null
237
     */
238
    public function getAddress(): ?Address
239
    {
240
        return $this->get('address');
241
    }
242
243
    /**
244
     * Seta o valor da propriedade address
245
     *
246
     * @param Address|null $address
247
     * @return self
248
     */
249
    public function setAddress(?Address $address = null): self
250
    {
251
        $this->set('address', $address);
252
        return $this;
253
    }
254
255
    /**
256
     * Retorna o valor da propriedade owner
257
     *
258
     * @return Owner|null
259
     */
260
    public function getOwner(): ?Owner
261
    {
262
        return $this->get('owner');
263
    }
264
265
    /**
266
     * Seta o valor da propriedade owner
267
     *
268
     * @param Owner|null $owner
269
     * @return self
270
     */
271
    public function setOwner(?Owner $owner = null): self
272
    {
273
        $this->set('owner', $owner);
274
        return $this;
275
    }
276
277
    /**
278
     * Retorna o valor da propriedade bank
279
     *
280
     * @return Bank|null
281
     */
282
    public function getBank(): ?Bank
283
    {
284
        return $this->get('bank');
285
    }
286
287
    /**
288
     * Seta o valor da propriedade bank
289
     *
290
     * @param Bank|null $bank
291
     * @return self
292
     */
293
    public function setBank(?Bank $bank = null): self
294
    {
295
        $this->set('bank', $bank);
296
        return $this;
297
    }
298
299
}