Completed
Pull Request — master (#150)
by
unknown
06:33
created

Variable::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Date: 23.11.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Parser\Ast\ArgumentValue;
9
10
use Youshido\GraphQL\Parser\Ast\AbstractAst;
11
use Youshido\GraphQL\Parser\Ast\Interfaces\ValueInterface;
12
use Youshido\GraphQL\Parser\Location;
13
14
class Variable extends AbstractAst implements ValueInterface
15
{
16
17
    /** @var  string */
18
    private $name;
19
20
    /** @var  mixed */
21
    private $value;
22
23
    /** @var string */
24
    private $type;
25
26
    /** @var bool */
27
    private $nullable = false;
28
29
    /** @var bool */
30
    private $isArray = false;
31
32
    /** @var bool */
33
    private $used = false;
34
35
    /** @var bool */
36
    private $arrayElementNullable = true;
37
38
    /** @var bool */
39
    private $hasDefaultValue = false;
40
41
    /** @var mixed */
42
    private $defaultValue = null;
43
44
    /**
45
     * @param string   $name
46
     * @param string   $type
47
     * @param bool     $nullable
48
     * @param bool     $isArray
49
     * @param Location $location
50
     * @param bool     $arrayElementNullable
51
     */
52 19
    public function __construct($name, $type, $nullable, $isArray, Location $location, $arrayElementNullable = true)
53
    {
54 19
        parent::__construct($location);
55
56 19
        $this->name                 = $name;
57 19
        $this->type                 = $type;
58 19
        $this->isArray              = $isArray;
59 19
        $this->nullable             = $nullable;
60 19
        $this->arrayElementNullable = $arrayElementNullable;
61 19
    }
62
63
    /**
64
     * @return mixed
65
     *
66
     * @throws \LogicException
67
     */
68 7
    public function getValue()
69
    {
70 7
        if (null === $this->value) {
71 3
            if ($this->hasDefaultValue()) {
72 1
                return $this->defaultValue;
73
            }
74 2
            throw new \LogicException('Value is not set for variable "' . $this->name . '"');
75
        }
76
77 4
        return $this->value;
78
    }
79
80
    /**
81
     * @param mixed $value
82
     */
83 11
    public function setValue($value)
84
    {
85 11
        $this->value = $value;
86 11
    }
87
88
    /**
89
     * @return string
90
     */
91 12
    public function getName()
92
    {
93 12
        return $this->name;
94
    }
95
96
    /**
97
     * @param string $name
98
     */
99 1
    public function setName($name)
100
    {
101 1
        $this->name = $name;
102 1
    }
103
104
    /**
105
     * @return string
106
     */
107 9
    public function getTypeName()
108
    {
109 9
        return $this->type;
110
    }
111
112
    /**
113
     * @param string $type
114
     */
115 1
    public function setTypeName($type)
116
    {
117 1
        $this->type = $type;
118 1
    }
119
120
    /**
121
     * @return boolean
122
     */
123 3
    public function isArray()
124
    {
125 3
        return $this->isArray;
126
    }
127
128
    /**
129
     * @param boolean $isArray
130
     */
131 1
    public function setIsArray($isArray)
132
    {
133 1
        $this->isArray = $isArray;
134 1
    }
135
136
    /**
137
     * @return boolean
138
     */
139 2
    public function isNullable()
140
    {
141 2
        return $this->nullable;
142
    }
143
144
    /**
145
     * @param boolean $nullable
146
     */
147 1
    public function setNullable($nullable)
148
    {
149 1
        $this->nullable = $nullable;
150 1
    }
151
152
    /**
153
     * @return bool
154
     */
155 5
    public function hasDefaultValue()
156
    {
157 5
        return $this->hasDefaultValue;
158
    }
159
160
    /**
161
     * @return mixed
162
     */
163
    public function getDefaultValue()
164
    {
165
        return $this->defaultValue;
166
    }
167
168
    /**
169
     * @param mixed $defaultValue
170
     */
171 3
    public function setDefaultValue($defaultValue)
172
    {
173 3
        $this->hasDefaultValue = true;
174
175 3
        $this->defaultValue = $defaultValue;
176 3
    }
177
178
    /**
179
     * @return boolean
180
     */
181 9
    public function isUsed()
182
    {
183 9
        return $this->used;
184
    }
185
186
    /**
187
     * @param boolean $used
188
     *
189
     * @return $this
190
     */
191 10
    public function setUsed($used)
192
    {
193 10
        $this->used = $used;
194
195 10
        return $this;
196
    }
197
198
    /**
199
     * @return bool
200
     */
201 1
    public function isArrayElementNullable()
202
    {
203 1
        return $this->arrayElementNullable;
204
    }
205
206
    /**
207
     * @param bool $arrayElementNullable
208
     */
209
    public function setArrayElementNullable($arrayElementNullable)
210
    {
211
        $this->arrayElementNullable = $arrayElementNullable;
212
    }
213
}
214