PropertyFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Metadata\Factory;
6
7
use LAG\AdminBundle\Exception\Validation\InvalidPropertyException;
8
use LAG\AdminBundle\Metadata\Property\PropertyInterface;
9
use Symfony\Component\Validator\Constraints\Valid;
10
use Symfony\Component\Validator\Validator\ValidatorInterface;
11
12
class PropertyFactory implements PropertyFactoryInterface
13
{
14
    public function __construct(
15
        private ValidatorInterface $validator,
16
    ) {
17
    }
18
19
    public function create(PropertyInterface $property): PropertyInterface
20
    {
21
        $errors = $this->validator->validate($property, [new Valid()]);
22
23
        if ($errors->count() > 0) {
24
            throw new InvalidPropertyException($property->getName(), $errors);
25
        }
26
27
        return $property;
28
    }
29
}
30