Validator::getValidatorClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
Bug Best Practice introduced by
The expression $interfaces of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
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