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

AnnotationMetadataBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Doctrine\Annotations\Metadata\Builder;
4
5
use Doctrine\Annotations\Metadata\AnnotationMetadata;
6
use Doctrine\Annotations\Metadata\AnnotationTarget;
7
use Doctrine\Annotations\Metadata\PropertyMetadata;
8
9
/**
10
 * @internal
11
 */
12
final class AnnotationMetadataBuilder
13
{
14
    /** @var string */
15
    private $name;
16
17
    /** @var AnnotationTarget */
18
    private $target;
19
20
    /** @var PropertyMetadata[] */
21
    private $properties = [];
22
23
    /** @var bool */
24
    private $usesConstructor = false;
25
26 292
    public function __construct(string $name)
27
    {
28 292
        $this->name   = $name;
29 292
        $this->target = AnnotationTarget::all();
30 292
    }
31
32 214
    public function withTarget(AnnotationTarget $target) : self
33
    {
34 214
        $new         = clone $this;
35 214
        $new->target = $target;
36
37 214
        return $new;
38
    }
39
40 134
    public function withUsingConstructor() : self
41
    {
42 134
        $new                  = clone $this;
43 134
        $new->usesConstructor = true;
44
45 134
        return $new;
46
    }
47
48 225
    public function withProperty(PropertyMetadata $property) : self
49
    {
50 225
        $new               = clone $this;
51 225
        $new->properties[] = $property;
52
53 225
        return $new;
54
    }
55
56 281
    public function build() : AnnotationMetadata
57
    {
58 281
        return new AnnotationMetadata(
59 281
            $this->name,
60 281
            $this->target,
61 281
            $this->usesConstructor,
62 281
            ...$this->properties
63
        );
64
    }
65
}
66