TypeDoc::addAllowedValue()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\Domain\Model\Type;
3
4
/**
5
 * Class TypeDoc
6
 */
7
class TypeDoc
8
{
9
    /*** Documentation ***/
10
    /** @var null|string|integer */
11
    private $name = null;
12
    /** @var null|string */
13
    private $description = null;
14
    /** @var null|mixed */
15
    private $default = null;
16
    /** @var null|mixed */
17
    private $example = null;
18
19
    /*** Validation ***/
20
    /** @var bool */
21
    private $required = false;
22
    /** @var bool */
23
    private $nullable = true;
24
    /** @var array */
25
    private $allowedValueList = [];
26
27
    /**
28
     * @param string|int $name
29
     *
30
     * @return self
31
     */
32 19
    public function setName($name) : self
33
    {
34 19
        if (null === $name || (!is_string($name) && !is_int($name))) {
35 4
            throw new \InvalidArgumentException('name must be either an integer or a string.');
36
        }
37
38 15
        $this->name = $name;
39
40 15
        return $this;
41
    }
42
43
    /**
44
     * @param string $description
45
     *
46
     * @return self
47
     */
48 11
    public function setDescription(string $description) : self
49
    {
50 11
        $this->description = $description;
51
52 11
        return $this;
53
    }
54
55
    /**
56
     * @param bool $required
57
     *
58
     * @return self
59
     */
60 14
    public function setRequired(bool $required = true) : self
61
    {
62 14
        $this->required = $required;
63
64 14
        return $this;
65
    }
66
67
    /**
68
     * @param bool $nullable
69
     *
70
     * @return self
71
     */
72 11
    public function setNullable(bool $nullable = true) : self
73
    {
74 11
        $this->nullable = $nullable;
75
76 11
        return $this;
77
    }
78
79
    /**
80
     * @param mixed|null $default
81
     *
82
     * @return self
83
     */
84 11
    public function setDefault($default) : self
85
    {
86 11
        $this->default = $default;
87
88 11
        return $this;
89
    }
90
91
    /**
92
     * @param mixed|null $example
93
     *
94
     * @return self
95
     */
96 11
    public function setExample($example) : self
97
    {
98 11
        $this->example = $example;
99
100 11
        return $this;
101
    }
102
103
    /**
104
     * @param mixed $allowedValue
105
     *
106
     * @return self
107
     */
108 11
    public function addAllowedValue($allowedValue) : self
109
    {
110 11
        $this->allowedValueList[] = $allowedValue;
111
112 11
        return $this;
113
    }
114
115
    /**
116
     * @return int|null|string
117
     */
118 5
    public function getName()
119
    {
120 5
        return $this->name;
121
    }
122
123
    /**
124
     * @return null|string
125
     */
126 24
    public function getDescription() : ?string
127
    {
128 24
        return $this->description;
129
    }
130
131
    /**
132
     * @return bool
133
     */
134 24
    public function isRequired() : bool
135
    {
136 24
        return $this->required;
137
    }
138
139
    /**
140
     * @return bool
141
     */
142 24
    public function isNullable() : bool
143
    {
144 24
        return $this->nullable;
145
    }
146
147
    /**
148
     * @return mixed|null
149
     */
150 24
    public function getDefault()
151
    {
152 24
        return $this->default;
153
    }
154
155
    /**
156
     * @return mixed|null
157
     */
158 24
    public function getExample()
159
    {
160 24
        return $this->example;
161
    }
162
163
    /**
164
     * @return mixed[]
165
     */
166 24
    public function getAllowedValueList() : array
167
    {
168 24
        return $this->allowedValueList;
169
    }
170
}
171