Failed Conditions
Push — annotation-metadata ( 414255 )
by Michael
02:42
created

PropertyMetadataBuilder::withEnum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Doctrine\Annotations\Metadata\Builder;
4
5
use Doctrine\Annotations\Metadata\PropertyMetadata;
6
7
final class PropertyMetadataBuilder
8
{
9
    /** @var string */
10
    private $name;
11
12
    /** @var string[]|null */
13
    private $type;
14
15
    /** @var bool */
16
    private $required = false;
17
18
    /** @var bool */
19
    private $default = false;
20
21
    /** @var mixed[]|null */
22
    private $enum;
23
24 177
    public function __construct(string $name)
25
    {
26 177
        $this->name = $name;
27 177
    }
28
29
    /**
30
     * @param string[] $type
31
     */
32 132
    public function withType(array $type) : self
33
    {
34 132
        $new       = clone $this;
35 132
        $new->type = $type;
36
37 132
        return $new;
38
    }
39
40 8
    public function withBeingRequired() : self
41
    {
42 8
        $new           = clone $this;
43 8
        $new->required = true;
44
45 8
        return $new;
46
    }
47
48 153
    public function withBeingDefault() : self
49
    {
50 153
        $new          = clone $this;
51 153
        $new->default = true;
52
53 153
        return $new;
54
    }
55
56
    /**
57
     * @param mixed[] $values
58
     */
59 4
    public function withEnum(array $enum) : self
60
    {
61 4
        $new       = clone $this;
62 4
        $new->enum = $enum;
63
64 4
        return $new;
65
    }
66
67 175
    public function build() : PropertyMetadata
68
    {
69 175
        return new PropertyMetadata(
70 175
            $this->name,
71 175
            $this->type,
72 175
            $this->required,
73 175
            $this->default,
74 175
            $this->enum
75
        );
76
    }
77
}
78