Failed Conditions
Push — metadata ( 4719fa )
by Michael
02:29
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
/**
8
 * @internal
9
 */
10
final class PropertyMetadataBuilder
11
{
12
    /** @var string */
13
    private $name;
14
15
    /** @var string[]|null */
16
    private $type;
17
18
    /** @var bool */
19
    private $required = false;
20
21
    /** @var bool */
22
    private $default = false;
23
24
    /** @var mixed[]|null */
25
    private $enum;
26
27 227
    public function __construct(string $name)
28
    {
29 227
        $this->name = $name;
30 227
    }
31
32
    /**
33
     * @param string[] $type
34
     */
35 182
    public function withType(array $type) : self
36
    {
37 182
        $new       = clone $this;
38 182
        $new->type = $type;
39
40 182
        return $new;
41
    }
42
43 9
    public function withBeingRequired() : self
44
    {
45 9
        $new           = clone $this;
46 9
        $new->required = true;
47
48 9
        return $new;
49
    }
50
51 156
    public function withBeingDefault() : self
52
    {
53 156
        $new          = clone $this;
54 156
        $new->default = true;
55
56 156
        return $new;
57
    }
58
59
    /**
60
     * @param mixed[] $values
61
     */
62 4
    public function withEnum(array $enum) : self
63
    {
64 4
        $new       = clone $this;
65 4
        $new->enum = $enum;
66
67 4
        return $new;
68
    }
69
70 225
    public function build() : PropertyMetadata
71
    {
72 225
        return new PropertyMetadata(
73 225
            $this->name,
74 225
            $this->type,
75 225
            $this->required,
76 225
            $this->default,
77 225
            $this->enum
78
        );
79
    }
80
}
81