1 | <?php |
||
53 | class Antibot |
||
54 | { |
||
55 | /** |
||
56 | * Antibot configuration |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $config; |
||
61 | /** |
||
62 | * Session persistent, unique token |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $unique; |
||
67 | /** |
||
68 | * Antibot prefix |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $prefix; |
||
73 | /** |
||
74 | * Unique signature |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $signature; |
||
79 | /** |
||
80 | * Parameter prefix |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $parameterPrefix; |
||
85 | /** |
||
86 | * GET & POST data |
||
87 | * |
||
88 | * @var null|string[] |
||
89 | */ |
||
90 | protected $data = null; |
||
91 | /** |
||
92 | * Validators |
||
93 | * |
||
94 | * @var ValidatorInterface[] |
||
95 | */ |
||
96 | protected $validators = []; |
||
97 | /** |
||
98 | * Actors |
||
99 | * |
||
100 | * @var ActorInterface[] |
||
101 | */ |
||
102 | protected $actors = []; |
||
103 | /** |
||
104 | * Immutable instance |
||
105 | * |
||
106 | * @var bool |
||
107 | */ |
||
108 | protected $immutable = false; |
||
109 | /** |
||
110 | * Default antibot prefix |
||
111 | * |
||
112 | * @var string |
||
113 | */ |
||
114 | const DEFAULT_PREFIX = 'antibot'; |
||
115 | |||
116 | /** |
||
117 | * Antibot constructor |
||
118 | * |
||
119 | * @param array $config Configuration |
||
120 | * @param string $unique Session-persistent, unique key |
||
121 | * @param string $prefix Prefix |
||
122 | */ |
||
123 | 7 | public function __construct($config, string $unique, string $prefix = self::DEFAULT_PREFIX) |
|
129 | |||
130 | /** |
||
131 | * Return the prefix |
||
132 | * |
||
133 | * @return string Prefix |
||
134 | */ |
||
135 | 1 | public function getPrefix(): string |
|
139 | |||
140 | /** |
||
141 | * Return the parameter prefix |
||
142 | * |
||
143 | * @return string Parameter prefix |
||
144 | * @throws RuntimeException If Antibot needs to be initialized |
||
145 | */ |
||
146 | 1 | public function getParameterPrefix(): string |
|
155 | |||
156 | /** |
||
157 | * Return the session persistent, unique token |
||
158 | * |
||
159 | * @return string Session persistent, unique token |
||
160 | */ |
||
161 | 1 | public function getUnique(): string |
|
165 | |||
166 | /** |
||
167 | * Return the submitted Antibot data |
||
168 | * |
||
169 | * @return string[] Antibot data |
||
170 | */ |
||
171 | 1 | public function getData(): ?array |
|
175 | |||
176 | /** |
||
177 | * Validate a request |
||
178 | * |
||
179 | * @param ServerRequestInterface $request Request |
||
180 | * |
||
181 | * @return ValidationResult Validation result |
||
182 | */ |
||
183 | 1 | public function validate(ServerRequestInterface $request): ValidationResult |
|
210 | |||
211 | /** |
||
212 | * Return the Antibot armor |
||
213 | * |
||
214 | * @param ServerRequestInterface $request Request |
||
215 | * |
||
216 | * @return string Antibot armor |
||
217 | */ |
||
218 | 1 | public function armor(ServerRequestInterface $request): string |
|
234 | |||
235 | /** |
||
236 | * Compare and sort validators |
||
237 | * |
||
238 | * @param ValidatorInterface $validator1 Validator 1 |
||
239 | * @param ValidatorInterface $validator2 Validator 2 |
||
240 | * |
||
241 | * @return int Sorting |
||
242 | */ |
||
243 | protected function sortValidators(ValidatorInterface $validator1, ValidatorInterface $validator2): int |
||
253 | |||
254 | /** |
||
255 | * Pre-validation initialization |
||
256 | * |
||
257 | * @param ServerRequestInterface $request Request |
||
258 | */ |
||
259 | 2 | protected function initialize(ServerRequestInterface $request): void |
|
267 | |||
268 | /** |
||
269 | * Calculate the unique signature |
||
270 | * |
||
271 | * @return string Signature |
||
272 | */ |
||
273 | 2 | protected function calculateSignature(): string |
|
279 | |||
280 | /** |
||
281 | * Extract the antibot data from GET and POST parameters |
||
282 | * |
||
283 | * @param ServerRequestInterface $request Request |
||
284 | */ |
||
285 | 2 | protected function extractData(ServerRequestInterface $request): void |
|
293 | |||
294 | /** |
||
295 | * Check whether this Antibot instance is immutable |
||
296 | * |
||
297 | * @throws RuntimeException If the Antibot instance is immutable |
||
298 | */ |
||
299 | 2 | protected function checkImmutable(): void |
|
308 | } |
||
309 |
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
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. 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.