Failed Conditions
Pull Request — master (#247)
by Michael
05:36
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
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 261
    public function __construct(string $name)
29
    {
30 261
        $this->name   = $name;
31 261
        $this->target = AnnotationTarget::all();
32 261
    }
33
34 204
    public function withTarget(AnnotationTarget $target) : self
35
    {
36 204
        $new         = clone $this;
37 204
        $new->target = $target;
38
39 204
        return $new;
40
    }
41
42 90
    public function withUsingConstructor() : self
43
    {
44 90
        $new                  = clone $this;
45 90
        $new->usesConstructor = true;
46
47 90
        return $new;
48
    }
49
50 236
    public function withProperty(PropertyMetadata $property) : self
51
    {
52 236
        $new               = clone $this;
53 236
        $new->properties[] = $property;
54
55 236
        return $new;
56
    }
57
58 253
    public function build() : AnnotationMetadata
59
    {
60 253
        return new AnnotationMetadata(
61 253
            $this->name,
62 253
            $this->target,
63 253
            $this->usesConstructor,
64 253
            ...$this->properties
65
        );
66
    }
67
}
68