Venue   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 155
rs 10
wmc 16

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setAddress() 0 4 1
A setCapacity() 0 4 1
A __construct() 0 3 1
A getName() 0 3 1
A getAddress() 0 3 1
A getCity() 0 3 1
A schema() 0 9 1
A state() 0 3 2
A getCapacity() 0 3 1
A capacity() 0 9 2
A getState() 0 3 1
A setState() 0 4 1
A setName() 0 4 1
A setCity() 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
use Ipag\Sdk\Util\StateUtil;
9
use Kubinyete\Assertation\Assert;
10
11
/**
12
 * Venue Class
13
 *
14
 * Classe responsável por representar o recurso Venue.
15
 *
16
 */
17
final class Venue extends Model
18
{
19
20
    /**
21
     *  @param array $data
22
     *  array de dados do Venue.
23
     *
24
     *  + [`'name'`] string (opcional).
25
     *  + [`'capacity'`] int (opcional).
26
     *  + [`'address'`] string (opcional).
27
     *  + [`'city'`] string (opcional).
28
     *  + [`'state'`] string (opcional).
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('name')->nullable();
38
        $schema->int('capacity')->nullable();
39
        $schema->string('address')->nullable();
40
        $schema->string('city')->nullable();
41
        $schema->string('state')->nullable();
42
43
        return $schema->build();
44
    }
45
46
    protected function capacity(): Mutator
47
    {
48
        return new Mutator(
49
            null,
50
            fn($value, $ctx) =>
51
            is_null($value) ? $value :
52
            (
53
                Assert::value(intval($value))->gt(0)->get()
54
                ?? $ctx->raise('inválido')
55
            )
56
        );
57
    }
58
59
    public function state(): Mutator
60
    {
61
        return new Mutator(null, fn($value) => !$value ? null : StateUtil::transformState($value));
62
    }
63
64
    /**
65
     * Retorna o valor da propriedade `name`.
66
     *
67
     * @return string|null
68
     */
69
    public function getName(): ?string
70
    {
71
        return $this->get('name');
72
    }
73
74
    /**
75
     * Seta o valor da propriedade `name`.
76
     *
77
     * @param string|null $name
78
     * @return self
79
     */
80
    public function setName(?string $name = null): self
81
    {
82
        $this->set('name', $name);
83
        return $this;
84
    }
85
86
    /**
87
     * Retorna o valor da propriedade `capacity`.
88
     *
89
     * @return integer|null
90
     */
91
    public function getCapacity(): ?int
92
    {
93
        return $this->get('capacity');
94
    }
95
96
    /**
97
     * Seta o valor da propriedade `capacity`.
98
     *
99
     * @param integer|null $capacity
100
     * @return self
101
     */
102
    public function setCapacity(?int $capacity = null): self
103
    {
104
        $this->set('capacity', $capacity);
105
        return $this;
106
    }
107
108
    /**
109
     * Retorna o valor da propriedade `address`.
110
     *
111
     * @return string|null
112
     */
113
    public function getAddress(): ?string
114
    {
115
        return $this->get('address');
116
    }
117
118
    /**
119
     * Seta o valor da propriedade `address`.
120
     *
121
     * @param string|null $address
122
     * @return self
123
     */
124
    public function setAddress(?string $address = null): self
125
    {
126
        $this->set('address', $address);
127
        return $this;
128
    }
129
130
    /**
131
     * Retorna o valor da propriedade `city`.
132
     *
133
     * @return string|null
134
     */
135
    public function getCity(): ?string
136
    {
137
        return $this->get('city');
138
    }
139
140
    /**
141
     * Seta o valor da propriedade `city`.
142
     *
143
     * @param string|null $city
144
     * @return self
145
     */
146
    public function setCity(?string $city = null): self
147
    {
148
        $this->set('city', $city);
149
        return $this;
150
    }
151
152
    /**
153
     * Retorna o valor da propriedade `state`.
154
     *
155
     * @return string|null
156
     */
157
    public function getState(): ?string
158
    {
159
        return $this->get('state');
160
    }
161
162
    /**
163
     * Seta o valor da propriedade `state`.
164
     *
165
     * @param string|null $state
166
     * @return self
167
     */
168
    public function setState(?string $state = null): self
169
    {
170
        $this->set('state', $state);
171
        return $this;
172
    }
173
174
}