Subscription   A
last analyzed

Complexity

Total Complexity 32

Size/Duplication

Total Lines 262
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 61
c 1
b 0
f 0
dl 0
loc 262
rs 9.84
wmc 32

22 Methods

Rating   Name   Duplication   Size   Complexity  
A plan_id() 0 9 3
A __construct() 0 3 1
A setClosingDate() 0 4 1
A setPlanId() 0 4 1
A setCallbackUrl() 0 4 1
A getCustomerId() 0 3 1
A getStartingDate() 0 3 1
A getClosingDate() 0 3 1
A getPlanId() 0 3 1
A closing_date() 0 10 4
A setIsActive() 0 4 1
A setCreditcardToken() 0 4 1
A schema() 0 12 1
A starting_date() 0 10 4
A getCreditcardToken() 0 3 1
A getCallbackUrl() 0 3 1
A getIsActive() 0 3 1
A getProfileId() 0 3 1
A setStartingDate() 0 4 1
A setProfileId() 0 4 1
A customer_id() 0 9 3
A setCustomerId() 0 4 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
9
/**
10
 * Subscription Class
11
 *
12
 * Classe responsável por representar o recurso Subscription.
13
 */
14
class Subscription extends Model
15
{
16
    /**
17
     *  @param array $data
18
     *  array de dados do Subscription.
19
     *
20
     *  + [`'is_active'`] bool.
21
     *  + [`'profile_id'`] string.
22
     *  + [`'plan_id'`] int.
23
     *  + [`'customer_id'`] int.
24
     *  + [`'starting_date'`] string (opcional) {`Formato: Y-m-d`}.
25
     *  + [`'closing_date'`] string (opcional) {`Formato: Y-m-d`}.
26
     *  + [`'callback_url'`] string (opcional).
27
     *  + [`'creditcard_token'`] string (opcional).
28
     */
29
    public function __construct(?array $data = [])
30
    {
31
        parent::__construct($data);
32
    }
33
34
    protected function schema(SchemaBuilder $schema): Schema
35
    {
36
        $schema->bool('is_active')->nullable();
37
        $schema->string('profile_id')->nullable();
38
        $schema->int('plan_id')->nullable();
39
        $schema->int('customer_id')->nullable();
40
        $schema->string('starting_date')->nullable();
41
        $schema->string('closing_date')->nullable();
42
        $schema->string('callback_url')->nullable();
43
        $schema->string('creditcard_token')->nullable();
44
45
        return $schema->build();
46
    }
47
48
    /**
49
     * Retorna o valor da propriedade `is_active`
50
     *
51
     * @return boolean|null
52
     */
53
    public function getIsActive(): ?bool
54
    {
55
        return $this->get('is_active');
56
    }
57
58
    /**
59
     * Seta o valor da propriedade `is_active`
60
     *
61
     * @param boolean|null $isActive
62
     * @return self
63
     */
64
    public function setIsActive(?bool $isActive = null): self
65
    {
66
        $this->set('is_active', $isActive);
67
        return $this;
68
    }
69
70
    /**
71
     * Retorna o valor da propriedade `profile_id`
72
     *
73
     * @return string|null
74
     */
75
    public function getProfileId(): ?string
76
    {
77
        return $this->get('profile_id');
78
    }
79
80
    /**
81
     * Seta o valor da propriedade `profile_id`
82
     *
83
     * @param string|null $profileId
84
     * @return self
85
     */
86
    public function setProfileId(?string $profileId = null): self
87
    {
88
        $this->set('profile_id', $profileId);
89
        return $this;
90
    }
91
92
    protected function plan_id(): Mutator
93
    {
94
        return new Mutator(
95
            null,
96
            fn($value, $ctx) =>
97
            is_null($value) ? $value :
98
            (
99
                (settype($value, 'int')) ? $value :
100
                $ctx->raise('inválido')
101
            )
102
        );
103
    }
104
105
    /**
106
     * Retorna o valor da propriedade `plan_id`
107
     *
108
     * @return integer|null
109
     */
110
    public function getPlanId(): ?int
111
    {
112
        return $this->get('plan_id');
113
    }
114
115
    /**
116
     * Seta o valor da propriedade `plan_id`
117
     *
118
     * @param integer|null $planId
119
     * @return self
120
     */
121
    public function setPlanId(?int $planId = null): self
122
    {
123
        $this->set('plan_id', $planId);
124
        return $this;
125
    }
126
127
    protected function customer_id(): Mutator
128
    {
129
        return new Mutator(
130
            null,
131
            fn($value, $ctx) =>
132
            is_null($value) ? $value :
133
            (
134
                (settype($value, 'int')) ? $value :
135
                $ctx->raise('inválido')
136
            )
137
        );
138
    }
139
140
    /**
141
     * Retorna o valor da propriedade `customer_id`
142
     *
143
     * @return integer|null
144
     */
145
    public function getCustomerId(): ?int
146
    {
147
        return $this->get('customer_id');
148
    }
149
150
    /**
151
     * Seta o valor da propriedade `customer_id`
152
     *
153
     * @param integer|null $customerId
154
     * @return self
155
     */
156
    public function setCustomerId(?int $customerId = null): self
157
    {
158
        $this->set('customer_id', $customerId);
159
        return $this;
160
    }
161
162
    protected function starting_date(): Mutator
163
    {
164
        return new Mutator(
165
            null,
166
            function ($value, $ctx) {
167
                $d = \DateTime::createFromFormat('Y-m-d', $value);
168
169
                return is_null($value) ||
170
                    ($d && $d->format('Y-m-d') === $value) ?
171
                    $value : $ctx->raise('inválido');
172
            }
173
        );
174
    }
175
176
    /**
177
     * Retorna o valor da propriedade `starting_date`
178
     *
179
     * @return string|null
180
     */
181
    public function getStartingDate(): ?string
182
    {
183
        return $this->get('starting_date');
184
    }
185
186
    /**
187
     * Seta o valor da propriedade `starting_date`
188
     *
189
     * @param string|null $startingDate
190
     * @return self
191
     */
192
    public function setStartingDate(?string $startingDate = null): self
193
    {
194
        $this->set('starting_date', $startingDate);
195
        return $this;
196
    }
197
198
    protected function closing_date(): Mutator
199
    {
200
        return new Mutator(
201
            null,
202
            function ($value, $ctx) {
203
                $d = \DateTime::createFromFormat('Y-m-d', $value);
204
205
                return is_null($value) ||
206
                    ($d && $d->format('Y-m-d') === $value) ?
207
                    $value : $ctx->raise('inválido');
208
            }
209
        );
210
    }
211
212
    /**
213
     * Retorna o valor da propriedade `closing_date`
214
     *
215
     * @return string|null
216
     */
217
    public function getClosingDate(): ?string
218
    {
219
        return $this->get('closing_date');
220
    }
221
222
    /**
223
     * Seta o valor da propriedade `closing_date`
224
     *
225
     * @param string|null $closingDate
226
     * @return self
227
     */
228
    public function setClosingDate(?string $closingDate = null): self
229
    {
230
        $this->set('closing_date', $closingDate);
231
        return $this;
232
    }
233
234
    /**
235
     * Retorna o valor da propriedade `callback_url`
236
     *
237
     * @return string|null
238
     */
239
    public function getCallbackUrl(): ?string
240
    {
241
        return $this->get('callback_url');
242
    }
243
244
    /**
245
     * Seta o valor da propriedade `callback_url`
246
     *
247
     * @param string|null $callbackUrl
248
     * @return self
249
     */
250
    public function setCallbackUrl(?string $callbackUrl = null): self
251
    {
252
        $this->set('callback_url', $callbackUrl);
253
        return $this;
254
    }
255
256
    /**
257
     * Retorna o valor da propriedade `creditcard_token`
258
     *
259
     * @return string|null
260
     */
261
    public function getCreditcardToken(): ?string
262
    {
263
        return $this->get('creditcard_token');
264
    }
265
266
    /**
267
     * Seta o valor da propriedade `creditcard_token`
268
     *
269
     * @param string|null $creditcardToken
270
     * @return self
271
     */
272
    public function setCreditcardToken(?string $creditcardToken = null): self
273
    {
274
        $this->set('creditcard_token', $creditcardToken);
275
        return $this;
276
    }
277
278
}