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

AnnotationMetadataBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 51
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 7 1
A __construct() 0 4 1
A withProperty() 0 6 1
A withUsingConstructor() 0 6 1
A withTarget() 0 6 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 261
    public function __construct(string $name)
27
    {
28 261
        $this->name   = $name;
29 261
        $this->target = AnnotationTarget::all();
30 261
    }
31
32 204
    public function withTarget(AnnotationTarget $target) : self
33
    {
34 204
        $new         = clone $this;
35 204
        $new->target = $target;
36
37 204
        return $new;
38
    }
39
40 90
    public function withUsingConstructor() : self
41
    {
42 90
        $new                  = clone $this;
43 90
        $new->usesConstructor = true;
44
45 90
        return $new;
46
    }
47
48 236
    public function withProperty(PropertyMetadata $property) : self
49
    {
50 236
        $new               = clone $this;
51 236
        $new->properties[] = $property;
52
53 236
        return $new;
54
    }
55
56 253
    public function build() : AnnotationMetadata
57
    {
58 253
        return new AnnotationMetadata(
59 253
            $this->name,
60 253
            $this->target,
61 253
            $this->usesConstructor,
62 253
            ...$this->properties
63
        );
64
    }
65
}
66