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

PropertyInstantiatorStrategy::construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 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