Validator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 18
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A getValidatorClassName() 0 3 1
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