|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cycle\Schema\Definition; |
|
6
|
|
|
|
|
7
|
|
|
use Cycle\ORM\Schema\GeneratedField; |
|
|
|
|
|
|
8
|
|
|
use Cycle\Schema\Definition\Map\OptionMap; |
|
9
|
|
|
use Cycle\Schema\Exception\FieldException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Field declaration, it's type and mapping to column. |
|
13
|
|
|
*/ |
|
14
|
|
|
final class Field |
|
15
|
|
|
{ |
|
16
|
|
|
private OptionMap $options; |
|
17
|
|
|
private OptionMap $attributes; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var non-empty-string|null |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
private ?string $column = null; |
|
23
|
1494 |
|
|
|
24
|
|
|
/** |
|
25
|
1494 |
|
* @var non-empty-string|null |
|
|
|
|
|
|
26
|
1494 |
|
*/ |
|
27
|
|
|
private ?string $type = null; |
|
28
|
58 |
|
|
|
29
|
|
|
private bool $primary = false; |
|
30
|
58 |
|
|
|
31
|
58 |
|
/** |
|
32
|
|
|
* @var callable-array|string|null |
|
|
|
|
|
|
33
|
712 |
|
*/ |
|
34
|
|
|
private array|string|null $typecast = null; |
|
35
|
712 |
|
|
|
36
|
|
|
private ?int $generated = null; |
|
37
|
|
|
|
|
38
|
1172 |
|
private bool $referenced = false; |
|
39
|
|
|
private ?string $entityClass = null; |
|
40
|
1172 |
|
|
|
41
|
2 |
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->options = new OptionMap(); |
|
44
|
1170 |
|
$this->attributes = new OptionMap(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1444 |
|
public function __clone() |
|
48
|
|
|
{ |
|
49
|
1444 |
|
$this->options = clone $this->options; |
|
50
|
|
|
$this->attributes = clone $this->attributes; |
|
51
|
1444 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getOptions(): OptionMap |
|
54
|
1254 |
|
{ |
|
55
|
|
|
return $this->options; |
|
56
|
1254 |
|
} |
|
57
|
|
|
|
|
58
|
1254 |
|
public function getAttributes(): OptionMap |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->attributes; |
|
61
|
1386 |
|
} |
|
62
|
|
|
|
|
63
|
1386 |
|
/** |
|
64
|
|
|
* @return non-empty-string |
|
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
1474 |
|
public function getType(): string |
|
67
|
|
|
{ |
|
68
|
1474 |
|
if (empty($this->type)) { |
|
69
|
|
|
throw new FieldException('Field type must be set'); |
|
70
|
1474 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this->type; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
972 |
|
* @param non-empty-string $type |
|
|
|
|
|
|
77
|
|
|
*/ |
|
78
|
972 |
|
public function setType(string $type): self |
|
79
|
2 |
|
{ |
|
80
|
|
|
$this->type = $type; |
|
81
|
|
|
|
|
82
|
970 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
958 |
|
public function setPrimary(bool $primary): self |
|
86
|
|
|
{ |
|
87
|
958 |
|
$this->primary = $primary; |
|
88
|
|
|
|
|
89
|
958 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
788 |
|
public function isPrimary(): bool |
|
93
|
|
|
{ |
|
94
|
788 |
|
return $this->primary || in_array($this->type, ['primary', 'bigPrimary']); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
958 |
|
/** |
|
98
|
|
|
* @param non-empty-string $column |
|
|
|
|
|
|
99
|
958 |
|
*/ |
|
100
|
|
|
public function setColumn(string $column): self |
|
101
|
|
|
{ |
|
102
|
952 |
|
$this->column = $column; |
|
103
|
|
|
|
|
104
|
952 |
|
return $this; |
|
105
|
|
|
} |
|
106
|
952 |
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @throws FieldException |
|
109
|
796 |
|
* |
|
110
|
|
|
* @return non-empty-string |
|
|
|
|
|
|
111
|
796 |
|
*/ |
|
112
|
|
|
public function getColumn(): string |
|
113
|
|
|
{ |
|
114
|
2 |
|
if (empty($this->column)) { |
|
115
|
|
|
throw new FieldException('Column mapping must be set'); |
|
116
|
2 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $this->column; |
|
119
|
952 |
|
} |
|
120
|
|
|
|
|
121
|
952 |
|
/** |
|
122
|
|
|
* @param callable-array|string|null $typecast |
|
|
|
|
|
|
123
|
952 |
|
*/ |
|
124
|
|
|
public function setTypecast(array|string|null $typecast): self |
|
125
|
|
|
{ |
|
126
|
|
|
$this->typecast = $typecast; |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function hasTypecast(): bool |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->typecast !== null; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return callable-array|string|null |
|
|
|
|
|
|
138
|
|
|
*/ |
|
139
|
|
|
public function getTypecast(): array|string|null |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->typecast; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param int|null $type Generating type {@see GeneratedField*} constants. |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setGenerated(int|null $type): self |
|
148
|
|
|
{ |
|
149
|
|
|
$this->generated = $type; |
|
150
|
|
|
|
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function getGenerated(): ?int |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->generated; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function setReferenced(bool $indexed): self |
|
160
|
|
|
{ |
|
161
|
|
|
$this->referenced = $indexed; |
|
162
|
|
|
|
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function isReferenced(): bool |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->referenced; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function getEntityClass(): ?string |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->entityClass; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function setEntityClass(?string $entityClass): self |
|
177
|
|
|
{ |
|
178
|
|
|
$this->entityClass = $entityClass; |
|
179
|
|
|
|
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths