Total Complexity | 4 |
Total Lines | 18 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
9 | #[Attribute(Attribute::TARGET_PROPERTY)] |
||
10 | class Validator |
||
11 | { |
||
12 | private string $validatorClassName; |
||
13 | |||
14 | public function __construct(string $validatorClassName) |
||
15 | { |
||
16 | $interfaces = class_implements($validatorClassName); |
||
17 | if ($interfaces && !in_array(CustomValidator::class, $interfaces, true)) { |
||
|
|||
18 | throw new RuntimeException("Custom validator must implement 'CustomValidator'"); |
||
19 | } |
||
20 | |||
21 | $this->validatorClassName = $validatorClassName; |
||
22 | } |
||
23 | |||
24 | public function getValidatorClassName(): string |
||
27 | } |
||
28 | } |
||
29 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.