PropertyFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 3

2 Methods

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