PropertyValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
c 0
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateProperty() 0 15 4
1
<?php
2
declare(strict_types=1);
3
4
namespace PrinsFrank\PhpStrictModels\Validation;
5
6
use PrinsFrank\PhpStrictModels\Rule\Rule;
7
use ReflectionProperty;
8
9
class PropertyValidator
10
{
11 3
    public static function validateProperty(ReflectionProperty $reflectionProperty, mixed $value): ValidationResult
12
    {
13 3
        $validationResult = new ValidationResult();
14 3
        foreach ($reflectionProperty->getAttributes() as $attribute) {
15 2
            $attributeInstance = $attribute->newInstance();
16 2
            if ($attributeInstance instanceof Rule === false) {
17 1
                continue;
18
            }
19
20 1
            if ($attributeInstance->isValid($value) === false) {
21 1
                $validationResult->addError($attributeInstance->getMessage());
22
            }
23
        }
24
25 3
        return $validationResult;
26
    }
27
}
28