Failed Conditions
Push — type ( c389f1...fc7bda )
by Michael
02:26
created

PropertyMetadataBuilder::withType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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