PropertyValidator::validateProperty()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 10
cc 4
nc 4
nop 2
crap 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