Failed Conditions
Pull Request — master (#247)
by Michael
05:15
created

AnnotationMetadata::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Metadata;
6
7
use function array_combine;
8
use function array_filter;
9
use function array_map;
10
use function array_values;
11
use function assert;
12
use function count;
13
14
/**
15
 * @internal
16
 */
17
final class AnnotationMetadata
18
{
19
    /** @var string */
20
    private $name;
21
22
    /** @var AnnotationTarget */
23
    private $target;
24
25
    /** @var bool */
26
    private $usesConstructor;
27
28
    /** @var PropertyMetadata[] */
29
    private $properties;
30
31
    /** @var PropertyMetadata|null */
32
    private $defaultProperty;
33
34
    /**
35
     * @param PropertyMetadata[] $properties
36
     */
37 294
    public function __construct(
38
        string $name,
39
        AnnotationTarget $target,
40
        bool $hasConstructor,
41
        PropertyMetadata ...$properties
42
    ) {
43 294
        $this->name           = $name;
44 294
        $this->target         = $target;
45 294
        $this->usesConstructor = $hasConstructor;
46 294
        $this->properties     = array_combine(
47 294
            array_map(
48
                static function (PropertyMetadata $property) : string {
49 291
                    return $property->getName();
50 294
                },
51 294
                $properties
52
            ),
53 294
            $properties
54
        );
55
56 294
        $defaultProperties = array_values(
57 294
            array_filter(
58 294
                $properties,
59
                static function (PropertyMetadata $property) : bool {
60 291
                    return $property->isDefault();
61 294
                }
62
            )
63
        );
64
65 294
        assert(count($defaultProperties) <= 1);
66
67 294
        $this->defaultProperty = $defaultProperties[0] ?? null;
68 294
    }
69
70 294
    public function getName() : string
71
    {
72 294
        return $this->name;
73
    }
74
75 261
    public function getTarget() : AnnotationTarget
76
    {
77 261
        return $this->target;
78
    }
79
80 250
    public function usesConstructor() : bool
81
    {
82 250
        return $this->usesConstructor;
83
    }
84
85
    /**
86
     * @return PropertyMetadata[]
87
     */
88 250
    public function getProperties() : array
89
    {
90 250
        return $this->properties;
91
    }
92
93 94
    public function getDefaultProperty() : ?PropertyMetadata
94
    {
95 94
        return $this->defaultProperty;
96
    }
97
}
98