1 | <?php declare(strict_types=1); |
||
2 | |||
3 | namespace Diezz\YamlToObjectMapper\Attributes; |
||
4 | |||
5 | use Attribute; |
||
6 | use Diezz\YamlToObjectMapper\CustomValidator; |
||
7 | use RuntimeException; |
||
8 | |||
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)) { |
||
0 ignored issues
–
show
|
|||
18 | throw new RuntimeException("Custom validator must implement 'CustomValidator'"); |
||
19 | } |
||
20 | |||
21 | $this->validatorClassName = $validatorClassName; |
||
22 | } |
||
23 | |||
24 | public function getValidatorClassName(): string |
||
25 | { |
||
26 | return $this->validatorClassName; |
||
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.