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

PropertyInstantiatorStrategy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A construct() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Constructor\Instantiator;
6
7
use Doctrine\Annotations\Metadata\AnnotationMetadata;
8
9
final class PropertyInstantiatorStrategy implements InstantiatorStrategy
10
{
11
    /**
12
     * @param mixed[] $parameters array<string, mixed>
13
     */
14 28
    public function construct(AnnotationMetadata $metadata, array $parameters) : object
15
    {
16 28
        $class      = $metadata->getName();
17 28
        $annotation = new $class();
18
19 28
        foreach ($parameters as $name => $value) {
20 12
            if ($name === '') {
21 6
                $name = $metadata->getDefaultProperty()->getName();
22
            }
23
24 12
            $annotation->$name = $value;
25
        }
26
27 28
        return $annotation;
28
    }
29
}
30