Passed
Pull Request — master (#10)
by Lucas
02:13
created

SplitRules::setSellerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Ipag\Sdk\Model;
4
5
use Ipag\Sdk\Model\Schema\Schema;
6
use Kubinyete\Assertation\Assert;
7
use Ipag\Sdk\Model\Schema\Mutator;
8
use Ipag\Sdk\Model\Schema\SchemaBuilder;
9
10
/**
11
 * SplitRules Class
12
 *
13
 * Classe responsável por representar o recurso Split Rules.
14
 */
15
class SplitRules extends Model
16
{
17
    /**
18
     *  @param array $data
19
     *  array de dados do Split Rules.
20
     *
21
     *  + [`'seller_id'`] string.
22
     *  + [`'amount'`] float.
23
     *  + [`'percentage'`] float.
24
     *  + [`'charge_processing_fee'`] bool.
25
     *  + [`'hold_receivables'`] bool.
26
     */
27
    public function __construct(?array $data = [])
28
    {
29
        parent::__construct($data);
30
    }
31
32
    protected function schema(SchemaBuilder $schema): Schema
33
    {
34
        $schema->string('seller_id')->nullable();
35
        $schema->float('amount')->nullable();
36
        $schema->float('percentage')->nullable();
37
        $schema->bool('charge_processing_fee')->nullable();
38
        $schema->bool('hold_receivables')->nullable();
39
40
        return $schema->build();
41
    }
42
43
    protected function amount(): Mutator
44
    {
45
        return new Mutator(
46
            null,
47
            fn ($value, $ctx) =>
48
            is_null($value) ? $value :
49
            (
50
                Assert::value(floatval($value))->gte(0)->get()
51
                ?? $ctx->raise('inválido')
52
            )
53
        );
54
    }
55
56
    protected function percentage(): Mutator
57
    {
58
        return new Mutator(
59
            null,
60
            fn ($value, $ctx) =>
61
            is_null($value) ? $value :
62
            (
63
                Assert::value(floatval($value))->gte(0)->get()
64
                ?? $ctx->raise('inválido')
65
            )
66
        );
67
    }
68
69
    /**
70
     * Retorna o valor da propriedade seller_id.
71
     *
72
     * @return string|null
73
     */
74
    public function getSellerId(): ?string
75
    {
76
        return $this->get('seller_id');
77
    }
78
79
    /**
80
     * Seta o valor da propriedade seller_id.
81
     *
82
     * @param string|null $sellerId
83
     * @return self
84
     */
85
    public function setSellerId(?string $sellerId = null): self
86
    {
87
        $this->set('seller_id', $sellerId);
88
89
        return $this;
90
    }
91
92
    /**
93
     * Retorna o valor da propriedade amount.
94
     *
95
     * @return float|null
96
     */
97
    public function getAmount(): ?float
98
    {
99
        return $this->get('amount');
100
    }
101
102
    /**
103
     * Seta o valor da propriedade amount.
104
     *
105
     * @param float|null $amount
106
     * @return self
107
     */
108
    public function setAmount(?float $amount = null): self
109
    {
110
        $this->set('amount', $amount);
111
        return $this;
112
    }
113
114
    /**
115
     * Retorna o valor da propriedade percentage.
116
     *
117
     * @return float|null
118
     */
119
    public function getPercentage(): ?float
120
    {
121
        return $this->get('percentage');
122
    }
123
124
    /**
125
     * Seta o valor da propriedade percentage.
126
     *
127
     * @param float|null $percentage
128
     * @return self
129
     */
130
    public function setPercentage(?float $percentage = null): self
131
    {
132
        $this->set('percentage', $percentage);
133
        return $this;
134
    }
135
136
    /**
137
     * Retorna o valor da propriedade charge_processing_fee.
138
     *
139
     * @return boolean|null
140
     */
141
    public function getChargeProcessingFee(): ?bool
142
    {
143
        return $this->get('charge_processing_fee');
144
    }
145
146
    /**
147
     * Seta o valor da propriedade charge_processing_fee.
148
     *
149
     * @param boolean|null $chargeProcessingFee
150
     * @return self
151
     */
152
    public function setChargeProcessingFee(?bool $chargeProcessingFee = null): self
153
    {
154
        $this->set('charge_processing_fee', $chargeProcessingFee);
155
        return $this;
156
    }
157
158
    /**
159
     * Retorna o valor da propriedade hold_receivables.
160
     *
161
     * @return boolean|null
162
     */
163
    public function getHoldReceivables(): ?bool
164
    {
165
        return $this->get('hold_receivables');
166
    }
167
168
    /**
169
     * Seta o valor da propriedade hold_receivables.
170
     *
171
     * @param boolean|null $holdReceivables
172
     * @return self
173
     */
174
    public function setHoldReceivables(?bool $holdReceivables = null): self
175
    {
176
        $this->set('hold_receivables', $holdReceivables);
177
        return $this;
178
    }
179
180
}
181