Passed
Pull Request — master (#247)
by Michael
02:00
created

AnnotationMetadataBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 48
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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