Completed
Pull Request — master (#247)
by Michael
02:36
created

AnnotationMetadataBuilder::withProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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