Token::getCard()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
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\Model\Schema\Mutator;
6
use Ipag\Sdk\Model\Schema\Schema;
7
use Ipag\Sdk\Model\Schema\SchemaBuilder;
8
9
/**
10
 * Token Class
11
 *
12
 * Classe responsável por representar o recurso Token.
13
 */
14
class Token extends Model
15
{
16
    /**
17
     *  @param array $data
18
     *  array de dados do Token.
19
     *
20
     *  + [`'value'`] string.
21
     *  + [`'validated_at'`] string.
22
     *  + [`'expires_at'`] string.
23
     *  + [`'Card'`] array (opcional) dos dados do Card.
24
     *  + &emsp; [`'holderName'`] string.
25
     *  + &emsp; [`'number'`] string.
26
     *  + &emsp; [`'expiryMonth'`] string.
27
     *  + &emsp; [`'expiryYear'`] string.
28
     *  + &emsp; [`'cvv'`] string.
29
     *  + [`'Holder'`] array (opcional) dos dados do Holder.
30
     *  + &emsp; [`'name'`] string.
31
     *  + &emsp; [`'cpfCnpj'`] string.
32
     *  + &emsp; [`'mobilePhone'`] string.
33
     *  + &emsp; [`'birthdate'`] string.
34
     *  + &emsp; [`'address'`] array (opcional) dos dados do Address.
35
     *  + &emsp;&emsp; [`'street'`] string (opcional).
36
     *  + &emsp;&emsp; [`'number'`] string (opcional).
37
     *  + &emsp;&emsp; [`'district'`] string (opcional).
38
     *  + &emsp;&emsp; [`'city'`] string (opcional).
39
     *  + &emsp;&emsp; [`'state'`] string (opcional).
40
     *  + &emsp;&emsp; [`'zipcode'`] string (opcional).
41
     */
42
    public function __construct(?array $data = [])
43
    {
44
        parent::__construct($data);
45
    }
46
47
    protected function schema(SchemaBuilder $schema): Schema
48
    {
49
        $schema->string('value')->nullable();
50
        $schema->string('validated_at')->nullable();
51
        $schema->string('expires_at')->nullable();
52
53
        $schema->has('card', Card::class)->nullable();
54
        $schema->has('holder', Holder::class)->nullable();
55
56
        return $schema->build();
57
    }
58
59
    /**
60
     * Retorna o valor da propriedade `value`.
61
     *
62
     * @return string|null
63
     */
64
    public function getValue(): ?string
65
    {
66
        return $this->get('value');
67
    }
68
69
    /**
70
     * Seta o valor da propriedade `value`.
71
     *
72
     * @param string|null $value
73
     * @return self
74
     */
75
    public function setValue(?string $value = null): self
76
    {
77
        $this->set('value', $value);
78
        return $this;
79
    }
80
81
    protected function validated_at(): Mutator
82
    {
83
        return new Mutator(
84
            null,
85
            function ($value, $ctx) {
86
                $d = \DateTime::createFromFormat('Y-m-d', $value);
87
88
                return is_null($value) ||
89
                    ($d && $d->format('Y-m-d') === $value) ?
90
                    $value : $ctx->raise('inválido');
91
            }
92
        );
93
    }
94
95
    /**
96
     * Retorna o valor da propriedade `validatedAt`.
97
     *
98
     * @return string|null
99
     */
100
    public function getValidatedAt(): ?string
101
    {
102
        return $this->get('validated_at');
103
    }
104
105
    /**
106
     * Seta o valor da propriedade `validatedAt`.
107
     *
108
     * @param string|null $validatedAt
109
     * @return self
110
     */
111
    public function setValidatedAt(?string $validatedAt = null): self
112
    {
113
        $this->set('validated_at', $validatedAt);
114
        return $this;
115
    }
116
117
    protected function expires_at(): Mutator
118
    {
119
        return new Mutator(
120
            null,
121
            function ($value, $ctx) {
122
                $d = \DateTime::createFromFormat('Y-m-d', $value);
123
124
                return is_null($value) ||
125
                    ($d && $d->format('Y-m-d') === $value) ?
126
                    $value : $ctx->raise('inválido');
127
            }
128
        );
129
    }
130
131
    /**
132
     * Retorna o valor da propriedade `expiresAt`.
133
     *
134
     * @return string|null
135
     */
136
    public function getExpiresAt(): ?string
137
    {
138
        return $this->get('expires_at');
139
    }
140
141
    /**
142
     * Seta o valor da propriedade `expiresAt`.
143
     *
144
     * @param string|null $expiresAt
145
     * @return self
146
     */
147
    public function setExpiresAt(?string $expiresAt = null): self
148
    {
149
        $this->set('expires_at', $expiresAt);
150
        return $this;
151
    }
152
153
    /**
154
     * Retorna o valor da propriedade `card`.
155
     *
156
     * @return Card|null
157
     */
158
    public function getCard(): ?Card
159
    {
160
        return $this->get('card');
161
    }
162
163
    /**
164
     * Seta o valor da propriedade `card`.
165
     *
166
     * @param Card|null $card
167
     * @return self
168
     */
169
    public function setCard(?Card $card = null): self
170
    {
171
        $this->set('card', $card);
172
        return $this;
173
    }
174
175
    /**
176
     * Retorna o valor da propriedade `holder`.
177
     *
178
     * @return Holder|null
179
     */
180
    public function getHolder(): ?Holder
181
    {
182
        return $this->get('holder');
183
    }
184
185
    /**
186
     * Seta o valor da propriedade `holder`.
187
     *
188
     * @param Holder|null $holder
189
     * @return self
190
     */
191
    public function setHolder(?Holder $holder = null): self
192
    {
193
        $this->set('holder', $holder);
194
        return $this;
195
    }
196
197
}