Failed Conditions
Push — metadata ( 4719fa )
by Michael
02:29
created

AnnotationMetadata::usesConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 330
    public function __construct(
38
        string $name,
39
        AnnotationTarget $target,
40
        bool $hasConstructor,
41
        PropertyMetadata ...$properties
42
    ) {
43 330
        $this->name           = $name;
44 330
        $this->target         = $target;
45 330
        $this->usesConstructor = $hasConstructor;
46 330
        $this->properties     = array_combine(
47 330
            array_map(
48
                static function (PropertyMetadata $property) : string {
49 330
                    return $property->getName();
50 330
                },
51 330
                $properties
52
            ),
53 330
            $properties
54
        );
55
56 330
        $defaultProperties = array_values(
57 330
            array_filter(
58 330
                $properties,
59
                static function (PropertyMetadata $property) : bool {
60 330
                    return $property->isDefault();
61 330
                }
62
            )
63
        );
64
65 330
        assert(count($defaultProperties) <= 1);
66
67 330
        $this->defaultProperty = $defaultProperties[0] ?? null;
68 330
    }
69
70 330
    public function getName() : string
71
    {
72 330
        return $this->name;
73
    }
74
75 292
    public function getTarget() : AnnotationTarget
76
    {
77 292
        return $this->target;
78
    }
79
80 275
    public function usesConstructor() : bool
81
    {
82 275
        return $this->usesConstructor;
83
    }
84
85
    /**
86
     * @return PropertyMetadata[]
87
     */
88 275
    public function getProperties() : array
89
    {
90 275
        return $this->properties;
91
    }
92
93 101
    public function getDefaultProperty() : ?PropertyMetadata
94
    {
95 101
        return $this->defaultProperty;
96
    }
97
}
98