Failed Conditions
Pull Request — new-parser-ast-metadata (#5)
by
unknown
02:14
created

Constructor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A construct() 0 21 4
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 37
    public function __construct(Instantiator $instantiator)
19
    {
20 37
        $this->instantiator = $instantiator;
21 37
    }
22
23
    /**
24
     * @param mixed[] $parameters iterable<string, mixed>
25
     */
26 28
    public function construct(AnnotationMetadata $annotationMetadata, Scope $scope, iterable $parameters) : object
27
    {
28 28
        (new TargetValidator())->validate($annotationMetadata, $scope);
29
30 28
        foreach ($parameters as $propertyName => $propertyValue) {
31 27
            if ($propertyName === '') {
32 20
                if ($annotationMetadata->hasConstructor()) {
33 20
                    continue;
34
                }
35
36 6
                $propertyName = $annotationMetadata->getDefaultProperty()->getName();
37
            }
38
39 18
            (new ValueValidator())->validate(
40 18
                $annotationMetadata,
41 18
                $annotationMetadata->getProperties()[$propertyName],
42 18
                $propertyValue
43
            );
44
        }
45
46 28
        return $this->instantiator->instantiate($annotationMetadata, $parameters);
47
    }
48
}
49