|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule\Skill; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Helper\Optionable; |
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
7
|
|
|
|
|
8
|
|
|
class Skill extends Optionable |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var string */ |
|
11
|
|
|
private $key; |
|
12
|
|
|
|
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
private $type; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string */ |
|
17
|
|
|
private $translation_key; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
private $type_translation_key; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
private $translation_domain; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Inducement constructor. |
|
27
|
|
|
* @param array $options |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
private function hydrateWithOptions($options) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->key = $options['key'] ?? false; |
|
|
|
|
|
|
33
|
|
|
$this->type = $options['type'] ?? false; |
|
|
|
|
|
|
34
|
|
|
$this->translation_key = $options['translation_key'] ?? false; |
|
|
|
|
|
|
35
|
|
|
$this->type_translation_key = $options['type_translation_key'] ?? false; |
|
|
|
|
|
|
36
|
|
|
$this->translation_domain = $options['translation_domain'] ?? false; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getKey(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->key; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $key |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setKey(string $key): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->key = $key; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getType(): string |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->type; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $type |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setType(string $type): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->type = $type; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getTranslationKey(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->translation_key; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $translation_key |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setTranslationKey(string $translation_key): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->translation_key = $translation_key; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getTypeTranslationKey(): string |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->type_translation_key; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param string $type_translation_key |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setTypeTranslationKey(string $type_translation_key): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->type_translation_key = $type_translation_key; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getTranslationDomain(): string |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->translation_domain; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param string $translation_domain |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setTranslationDomain(string $translation_domain): void |
|
115
|
|
|
{ |
|
116
|
|
|
$this->translation_domain = $translation_domain; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function __toString(): string |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->translation_key; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function resolveOptions($options) |
|
125
|
|
|
{ |
|
126
|
|
|
parent::resolveOptions($options); |
|
127
|
|
|
$this->hydrateWithOptions($options); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
131
|
|
|
{ |
|
132
|
|
|
$resolver->setDefaults([ |
|
133
|
|
|
'key' => null, |
|
134
|
|
|
'type' => null, |
|
135
|
|
|
'translation_key' => null, |
|
136
|
|
|
'translation_domain' => null, |
|
137
|
|
|
'type_translation_key' => null, |
|
138
|
|
|
]) |
|
139
|
|
|
->setRequired('key') |
|
140
|
|
|
->setRequired('translation_key') |
|
141
|
|
|
->setRequired('translation_domain') |
|
142
|
|
|
->setRequired('type') |
|
143
|
|
|
->setRequired('type_translation_key') |
|
144
|
|
|
->setAllowedTypes('key', ['string']) |
|
145
|
|
|
->setAllowedTypes('translation_key', ['string']) |
|
146
|
|
|
->setAllowedTypes('translation_domain', ['string']) |
|
147
|
|
|
->setAllowedTypes('type', ['string']) |
|
148
|
|
|
->setAllowedTypes('type_translation_key', ['string']) |
|
149
|
|
|
; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
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 mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.