Constructor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 34
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A construct() 0 21 4
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Constructor;
6
7
use Doctrine\Annotations\Assembler\Validator\TargetValidator;
8
use Doctrine\Annotations\Assembler\Validator\ValueValidator;
9
use Doctrine\Annotations\Constructor\Instantiator\Instantiator;
10
use Doctrine\Annotations\Metadata\AnnotationMetadata;
11
use Doctrine\Annotations\Parser\Scope;
12
13
final class Constructor
14
{
15
    /** @var Instantiator */
16
    private $instantiator;
17
18 9
    public function __construct(Instantiator $instantiator)
19
    {
20 9
        $this->instantiator = $instantiator;
21 9
    }
22
23
    /**
24
     * @param mixed[] $parameters iterable<string, mixed>
25
     */
26 9
    public function construct(AnnotationMetadata $annotationMetadata, Scope $scope, iterable $parameters) : object
27
    {
28 9
        (new TargetValidator())->validate($annotationMetadata, $scope);
29
30 9
        foreach ($parameters as $propertyName => $propertyValue) {
31 9
            if ($propertyName === '') {
32 6
                if ($annotationMetadata->hasConstructor()) {
33 6
                    continue;
34
                }
35
36
                $propertyName = $annotationMetadata->getDefaultProperty()->getName();
37
            }
38
39 4
            (new ValueValidator())->validate(
40 4
                $annotationMetadata,
41 4
                $annotationMetadata->getProperties()[$propertyName],
42 4
                $propertyValue
43
            );
44
        }
45
46 9
        return $this->instantiator->instantiate($annotationMetadata, $parameters);
47
    }
48
}
49