Failed Conditions
Push — annotation-metadata ( 414255 )
by Michael
02:42
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 withConstructor() 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
final class AnnotationMetadataBuilder
10
{
11
    /** @var string */
12
    private $name;
13
14
    /** @var AnnotationTarget */
15
    private $target;
16
17
    /** @var PropertyMetadata[] */
18
    private $properties = [];
19
20
    /** @var bool */
21
    private $constructor = false;
22
23 242
    public function __construct(string $name)
24
    {
25 242
        $this->name   = $name;
26 242
        $this->target = AnnotationTarget::all();
27 242
    }
28
29 164
    public function withTarget(AnnotationTarget $target) : self
30
    {
31 164
        $new         = clone $this;
32 164
        $new->target = $target;
33
34 164
        return $new;
35
    }
36
37 84
    public function withConstructor() : self
38
    {
39 84
        $new              = clone $this;
40 84
        $new->constructor = true;
41
42 84
        return $new;
43
    }
44
45 175
    public function withProperty(PropertyMetadata $property) : self
46
    {
47 175
        $new               = clone $this;
48 175
        $new->properties[] = $property;
49
50 175
        return $new;
51
    }
52
53 231
    public function build() : AnnotationMetadata
54
    {
55 231
        return new AnnotationMetadata(
56 231
            $this->name,
57 231
            $this->target,
58 231
            $this->constructor,
59 231
            ...$this->properties
60
        );
61
    }
62
}
63