Issues (23)

src/Model/PaymentCard.php (1 issue)

Labels
Severity
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
 * PaymentCard Class
12
 *
13
 * Classe responsável por representar o recurso PaymentCard.
14
 *
15
 */
16
final class PaymentCard extends Model
17
{
18
    /**
19
     *  @param array $data
20
     *  array de dados do Card.
21
     *
22
     *  + [`'holder'`] string.
23
     *  + [`'number'`] string.
24
     *  + [`'expiry_month'`] string.
25
     *  + [`'expiry_year'`] string.
26
     *  + [`'cvv'`] string.
27
     *  + [`'token'`] string.
28
     *  + [`'tokenize'`] bool.
29
     */
30
    public function __construct(?array $data = [])
31
    {
32
        parent::__construct($data);
33
    }
34
35
    public function schema(SchemaBuilder $schema): Schema
36
    {
37
        $schema->string('holder')->nullable();
38
        $schema->string('number')->nullable();
39
        $schema->string('expiry_month')->nullable();
40
        $schema->string('expiry_year')->nullable();
41
        $schema->string('cvv')->nullable();
42
        $schema->string('token')->nullable();
43
        $schema->bool('tokenize')->nullable();
44
45
        return $schema->build();
46
    }
47
48
    protected function number(): Mutator
49
    {
50
        return new Mutator(null, fn($value) => Assert::value($value)->asDigits()->get());
51
    }
52
53
    protected function expiry_month(): Mutator
54
    {
55
        return new Mutator(
56
            null,
57
            fn($value, $ctx) =>
58
            is_null($value) ? $value
59
            :
60
            (
61
                str_pad(
62
                    Assert::value(intval($value))->between(1, 12)->get()
0 ignored issues
show
It seems like Kubinyete\Assertation\As...um valor de 01 à 12)') can also be of type mixed; however, parameter $string of str_pad() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
                    /** @scrutinizer ignore-type */ Assert::value(intval($value))->between(1, 12)->get()
Loading history...
63
                    ?? $ctx->raise('inválido (informe um valor de 01 à 12)')
64
                    ,
65
                    2,
66
                    '0',
67
                    STR_PAD_LEFT
68
                )
69
            )
70
71
        );
72
    }
73
74
    protected function expiry_year(): Mutator
75
    {
76
        return new Mutator(
77
            null,
78
            fn($value, $ctx) =>
79
            is_null($value) ? $value :
80
            (
81
                Assert::value($value)->asDigits()->lbetween(2, 2)->or()->lbetween(4, 4)->get() ?? $ctx->raise('inválido (informe um valor numérico de 2 ou 4 dígitos)')
82
            )
83
        );
84
    }
85
86
    protected function cvv(): Mutator
87
    {
88
        return new Mutator(
89
            null,
90
            fn($value, $ctx) =>
91
            is_null($value) ? $value :
92
            (
93
                Assert::value($value)->asDigits()->lbetween(3, 3)->or()->lbetween(4, 4)->get() ?? $ctx->raise('inválido (informe um valor numérico de 3 ou 4 dígitos)')
94
            )
95
        );
96
    }
97
98
    /**
99
     * Retorna o valor da propriedade `holder`.
100
     *
101
     * @return string|null
102
     */
103
    public function getHolder(): ?string
104
    {
105
        return $this->get('holder');
106
    }
107
108
    /**
109
     * Seta o valor da propriedade `holder`.
110
     *
111
     * @param string|null $holder
112
     * @return self
113
     */
114
    public function setHolder(?string $holder = null): self
115
    {
116
        $this->set('holder', $holder);
117
        return $this;
118
    }
119
120
    /**
121
     * Retorna o valor da propriedade `number`.
122
     *
123
     * @return string|null
124
     */
125
    public function getNumber(): ?string
126
    {
127
        return $this->get('number');
128
    }
129
130
    /**
131
     * Seta o valor da propriedade `number`.
132
     *
133
     * @param string|null $number
134
     * @return self
135
     */
136
    public function setNumber(?string $number = null): self
137
    {
138
        $this->set('number', $number);
139
        return $this;
140
    }
141
142
    /**
143
     * Retorna o valor da propriedade `expiry_month`.
144
     *
145
     * @return string|null
146
     */
147
    public function getExpiryMonth(): ?string
148
    {
149
        return $this->get('expiry_month');
150
    }
151
152
    /**
153
     * Seta o valor da propriedade `expiry_month`
154
     *
155
     * @param string|null $expiry_month
156
     * @return self
157
     */
158
    public function setExpiryMonth(?string $expiry_month = null): self
159
    {
160
        $this->set('expiry_month', $expiry_month);
161
        return $this;
162
    }
163
164
    /**
165
     * Retorna o valor da propriedade `expiry_year`.
166
     *
167
     * @return string|null
168
     */
169
    public function getExpiryYear(): ?string
170
    {
171
        return $this->get('expiry_year');
172
    }
173
174
    /**
175
     * Seta o valor da propriedade `expiry_year`
176
     *
177
     * @param string|null $expiry_year
178
     * @return self
179
     */
180
    public function setExpiryYear(?string $expiry_year = null): self
181
    {
182
        $this->set('expiry_year', $expiry_year);
183
        return $this;
184
    }
185
186
    /**
187
     * Retorna o valor da propriedade `token`.
188
     *
189
     * @return string|null
190
     */
191
    public function getToken(): ?string
192
    {
193
        return $this->get('token');
194
    }
195
196
    /**
197
     * Seta o valor da propriedade `token`
198
     *
199
     * @param string|null $token
200
     * @return self
201
     */
202
    public function setToken(?string $token = null): self
203
    {
204
        $this->set('token', $token);
205
        return $this;
206
    }
207
208
    /**
209
     * Retorna o valor da propriedade `cvv`.
210
     *
211
     * @return string|null
212
     */
213
    public function getCvv(): ?string
214
    {
215
        return $this->get('cvv');
216
    }
217
218
    /**
219
     * Seta o valor da propriedade `cvv`
220
     *
221
     * @param string|null $cvv
222
     * @return self
223
     */
224
    public function setCvv(?string $cvv = null): self
225
    {
226
        $this->set('cvv', $cvv);
227
        return $this;
228
    }
229
230
    /**
231
     * Retorna o valor da propriedade `tokenize`.
232
     *
233
     * @return boolean|null
234
     */
235
    public function getTokenize(): ?bool
236
    {
237
        return $this->get('tokenize');
238
    }
239
240
    /**
241
     * Seta o valor da propriedade `tokenize`
242
     *
243
     * @param boolean|null $tokenize
244
     * @return self
245
     */
246
    public function setTokenize(?bool $tokenize = null): self
247
    {
248
        $this->set('tokenize', $tokenize);
249
        return $this;
250
    }
251
252
}