Failed Conditions
Pull Request — feature/init (#3)
by Yo
01:46
created

TypeDoc::setDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\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 null|string|integer $name
29
     *
30
     * @return TypeDoc
31
     */
32
    public function setName($name) : TypeDoc
33
    {
34
        if (null !== $name && !is_string($name) && !is_int($name)) {
1 ignored issue
show
introduced by
The condition is_int($name) is always true.
Loading history...
35
            throw new \InvalidArgumentException('name must be either null, an integer or a string.');
36
        }
37
38
        $this->name = $name;
39
40
        return $this;
41
    }
42
43
    /**
44
     * @param string $description
45
     *
46
     * @return TypeDoc
47
     */
48
    public function setDescription(string $description) : TypeDoc
49
    {
50
        $this->description = $description;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param bool $required
57
     *
58
     * @return TypeDoc
59
     */
60
    public function setRequired(bool $required) : TypeDoc
61
    {
62
        $this->required = $required;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param bool $nullable
69
     *
70
     * @return TypeDoc
71
     */
72
    public function setNullable(bool $nullable) : TypeDoc
73
    {
74
        $this->nullable = $nullable;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @param mixed|null $default
81
     *
82
     * @return TypeDoc
83
     */
84
    public function setDefault($default) : TypeDoc
85
    {
86
        $this->default = $default;
87
88
        return $this;
89
    }
90
91
    /**
92
     * @param mixed|null $example
93
     *
94
     * @return TypeDoc
95
     */
96
    public function setExample($example) : TypeDoc
97
    {
98
        $this->example = $example;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @param array $allowedValueList
105
     *
106
     * @return TypeDoc
107
     */
108
    public function addAllowedValue($allowedValue) : TypeDoc
109
    {
110
        $this->allowedValueList[] = $allowedValue;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @param array $allowedValueList
117
     *
118
     * @return TypeDoc
119
     */
120
    public function setAllowedValueList(array $allowedValueList) : TypeDoc
121
    {
122
        $this->allowedValueList = $allowedValueList;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return int|null|string
129
     */
130
    public function getName()
131
    {
132
        return $this->name;
133
    }
134
135
    /**
136
     * @return null|string
137
     */
138
    public function getDescription()
139
    {
140
        return $this->description;
141
    }
142
143
    /**
144
     * @return bool
145
     */
146
    public function isRequired() : bool
147
    {
148
        return $this->required;
149
    }
150
151
    /**
152
     * @return bool
153
     */
154
    public function isNullable()
155
    {
156
        return $this->nullable;
157
    }
158
159
    /**
160
     * @return mixed|null
161
     */
162
    public function getDefault()
163
    {
164
        return $this->default;
165
    }
166
167
    /**
168
     * @return mixed|null
169
     */
170
    public function getExample()
171
    {
172
        return $this->example;
173
    }
174
175
    /**
176
     * @return array
177
     */
178
    public function getAllowedValueList()
179
    {
180
        return $this->allowedValueList;
181
    }
182
}
183