1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule\Roster; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Contracts\PositionInterface; |
6
|
|
|
use Obblm\Core\Contracts\RosterInterface; |
7
|
|
|
use Obblm\Core\Helper\Optionable; |
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
9
|
|
|
|
10
|
|
|
abstract class AbstractPosition extends Optionable implements PositionInterface |
11
|
|
|
{ |
12
|
|
|
/** @var string */ |
13
|
|
|
private $key; |
14
|
|
|
/** @var string */ |
15
|
|
|
private $name; |
16
|
|
|
/** @var string */ |
17
|
|
|
private $translationDomain; |
18
|
|
|
/** @var int */ |
19
|
|
|
private $cost; |
20
|
|
|
/** @var int */ |
21
|
|
|
private $min; |
22
|
|
|
/** @var int */ |
23
|
|
|
private $max; |
24
|
|
|
/** @var bool */ |
25
|
|
|
private $isJourneyman; |
26
|
|
|
/** @var array */ |
27
|
|
|
private $characteristics; |
28
|
|
|
/** @var array */ |
29
|
|
|
private $skills; |
30
|
|
|
/** @var array */ |
31
|
|
|
private $availableSkills; |
32
|
|
|
/** @var array */ |
33
|
|
|
private $availableSkillsOnDouble; |
34
|
|
|
/** @var roster */ |
35
|
|
|
private $roster; |
36
|
|
|
|
37
|
1 |
|
protected function hydrateWithOptions() |
38
|
|
|
{ |
39
|
1 |
|
$this->setKey($this->options['key']) |
40
|
1 |
|
->setName($this->options['name']) |
41
|
1 |
|
->setTranslationDomain($this->options['translation_domain']) |
42
|
1 |
|
->setCharacteristics($this->options['characteristics']) |
43
|
1 |
|
->setCost($this->options['cost']) |
44
|
1 |
|
->setMin($this->options['min']) |
45
|
1 |
|
->setMax($this->options['max']) |
46
|
1 |
|
->setIsJourneyman($this->options['is_journeyman']) |
47
|
1 |
|
->setSkills($this->options['skills']) |
48
|
1 |
|
->setAvailableSkills($this->options['available_skills']) |
49
|
1 |
|
->setAvailableSkillsOnDouble($this->options['available_skills_on_double']) |
50
|
|
|
; |
51
|
1 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getKey(): string |
57
|
|
|
{ |
58
|
|
|
return $this->key; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function getName(): string |
65
|
|
|
{ |
66
|
|
|
return $this->name; |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
public function getMax(): int |
70
|
|
|
{ |
71
|
1 |
|
return $this->max; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getCost(): int |
75
|
|
|
{ |
76
|
|
|
return $this->cost; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function isJourneyman(): bool |
80
|
|
|
{ |
81
|
|
|
return $this->isJourneyman; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getIsJourneyman(): bool |
85
|
|
|
{ |
86
|
|
|
return $this->isJourneyman; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return int |
91
|
|
|
*/ |
92
|
|
|
public function getMin(): int |
93
|
|
|
{ |
94
|
|
|
return $this->min; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
public function getSkills(): array |
101
|
|
|
{ |
102
|
|
|
return $this->skills; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getCharacteristics(): array |
109
|
|
|
{ |
110
|
|
|
return $this->characteristics; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function getAvailableSkills(): array |
117
|
|
|
{ |
118
|
|
|
return $this->availableSkills; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
|
|
public function getAvailableSkillsOnDouble(): array |
125
|
|
|
{ |
126
|
|
|
return $this->availableSkillsOnDouble; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return RosterInterface |
131
|
|
|
*/ |
132
|
|
|
public function getRoster(): RosterInterface |
133
|
|
|
{ |
134
|
|
|
return $this->roster; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getTranslationDomain(): string |
142
|
|
|
{ |
143
|
|
|
return $this->translationDomain; |
144
|
|
|
} |
145
|
|
|
|
146
|
1 |
|
public function setKey(string $key): self |
147
|
|
|
{ |
148
|
1 |
|
$this->key = $key; |
149
|
1 |
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
1 |
|
public function setRoster(RosterInterface $roster): self |
153
|
|
|
{ |
154
|
1 |
|
$this->roster = $roster; |
|
|
|
|
155
|
1 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
1 |
|
public function setName(string $name): self |
159
|
|
|
{ |
160
|
1 |
|
$this->name = $name; |
161
|
1 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
1 |
|
public function setTranslationDomain(string $translationDomain): self |
165
|
|
|
{ |
166
|
1 |
|
$this->translationDomain = $translationDomain; |
167
|
1 |
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param int $cost |
172
|
|
|
*/ |
173
|
1 |
|
public function setCost(int $cost): self |
174
|
|
|
{ |
175
|
1 |
|
$this->cost = $cost; |
176
|
1 |
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param int $min |
181
|
|
|
*/ |
182
|
1 |
|
public function setMin(int $min): self |
183
|
|
|
{ |
184
|
1 |
|
$this->min = $min; |
185
|
1 |
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param int $max |
190
|
|
|
*/ |
191
|
1 |
|
public function setMax(int $max): self |
192
|
|
|
{ |
193
|
1 |
|
$this->max = $max; |
194
|
1 |
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param bool $isJouneyman |
199
|
|
|
*/ |
200
|
1 |
|
public function setIsJourneyman(bool $isJourneyman): self |
201
|
|
|
{ |
202
|
1 |
|
$this->isJourneyman = $isJourneyman; |
203
|
1 |
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param array |
208
|
|
|
*/ |
209
|
1 |
|
public function setCharacteristics(array $characteristics): self |
210
|
|
|
{ |
211
|
1 |
|
$this->characteristics = $characteristics; |
212
|
1 |
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param array $skills |
217
|
|
|
*/ |
218
|
1 |
|
public function setSkills(array $skills): self |
219
|
|
|
{ |
220
|
1 |
|
$this->skills = $skills; |
221
|
1 |
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param array $availableSkills |
226
|
|
|
*/ |
227
|
1 |
|
public function setAvailableSkills(array $availableSkills): self |
228
|
|
|
{ |
229
|
1 |
|
$this->availableSkills = $availableSkills; |
230
|
1 |
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param array $availableSkillsOnDouble |
235
|
|
|
*/ |
236
|
1 |
|
public function setAvailableSkillsOnDouble(array $availableSkillsOnDouble): self |
237
|
|
|
{ |
238
|
1 |
|
$this->availableSkillsOnDouble = $availableSkillsOnDouble; |
239
|
1 |
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function __toString(): string |
243
|
|
|
{ |
244
|
|
|
return $this->name; |
245
|
|
|
} |
246
|
|
|
|
247
|
1 |
|
public function configureOptions(OptionsResolver $resolver):void |
248
|
|
|
{ |
249
|
1 |
|
$resolver->setDefaults([ |
250
|
1 |
|
'key' => null, |
251
|
|
|
'name' => null, |
252
|
|
|
'translation_domain' => null, |
253
|
|
|
'characteristics' => null, |
254
|
|
|
'skills' => [], |
255
|
|
|
'available_skills' => [], |
256
|
|
|
'available_skills_on_double' => [], |
257
|
|
|
'min' => 1, |
258
|
|
|
'max' => 1, |
259
|
|
|
'cost' => null, |
260
|
|
|
'is_journeyman' => false, |
261
|
|
|
]) |
262
|
1 |
|
->setRequired(['key', 'name', 'translation_domain', 'characteristics']) |
263
|
1 |
|
->setAllowedTypes('key', ['string']) |
264
|
1 |
|
->setAllowedTypes('name', ['string']) |
265
|
1 |
|
->setAllowedTypes('translation_domain', ['string']) |
266
|
1 |
|
->setAllowedTypes('characteristics', ['array']) |
267
|
1 |
|
->setAllowedTypes('skills', ['array']) |
268
|
1 |
|
->setAllowedTypes('available_skills', ['array']) |
269
|
1 |
|
->setAllowedTypes('available_skills_on_double', ['array']) |
270
|
1 |
|
->setAllowedTypes('min', ['int']) |
271
|
1 |
|
->setAllowedTypes('max', ['int']) |
272
|
1 |
|
->setAllowedTypes('cost', ['int']) |
273
|
1 |
|
->setAllowedTypes('is_journeyman', ['bool']) |
274
|
|
|
; |
275
|
1 |
|
} |
276
|
|
|
} |
277
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.