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

PropertyMetadataBuilder::withType()   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
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