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

PropertyMetadataBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 25
dl 0
loc 68
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A withType() 0 6 1
A build() 0 8 1
A withBeingRequired() 0 6 1
A withEnum() 0 6 1
A withBeingDefault() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Metadata\Builder;
6
7
use Doctrine\Annotations\Metadata\PropertyMetadata;
8
9
/**
10
 * @internal
11
 */
12
final class PropertyMetadataBuilder
13
{
14
    /** @var string */
15
    private $name;
16
17
    /** @var string[]|null */
18
    private $type;
19
20
    /** @var bool */
21
    private $required = false;
22
23
    /** @var bool */
24
    private $default = false;
25
26
    /** @var mixed[]|null */
27
    private $enum;
28
29 239
    public function __construct(string $name)
30
    {
31 239
        $this->name = $name;
32 239
    }
33
34
    /**
35
     * @param string[] $type
36
     */
37 174
    public function withType(array $type) : self
38
    {
39 174
        $new       = clone $this;
40 174
        $new->type = $type;
41
42 174
        return $new;
43
    }
44
45 4
    public function withBeingRequired() : self
46
    {
47 4
        $new           = clone $this;
48 4
        $new->required = true;
49
50 4
        return $new;
51
    }
52
53 169
    public function withBeingDefault() : self
54
    {
55 169
        $new          = clone $this;
56 169
        $new->default = true;
57
58 169
        return $new;
59
    }
60
61
    /**
62
     * @param mixed[] $enum
63
     */
64 4
    public function withEnum(array $enum) : self
65
    {
66 4
        $new       = clone $this;
67 4
        $new->enum = $enum;
68
69 4
        return $new;
70
    }
71
72 237
    public function build() : PropertyMetadata
73
    {
74 237
        return new PropertyMetadata(
75 237
            $this->name,
76 237
            $this->type,
77 237
            $this->required,
78 237
            $this->default,
79 237
            $this->enum
80
        );
81
    }
82
}
83