1 | <?php |
||
10 | class Variable |
||
11 | { |
||
12 | const BRANCH_ROOT = 0; |
||
13 | |||
14 | const BRANCH_CONDITIONAL_TRUE = 1; |
||
15 | |||
16 | const BRANCH_CONDITIONAL_FALSE = 2; |
||
17 | |||
18 | const BRANCH_CONDITIONAL_EXTERNAL = 3; |
||
19 | |||
20 | const BRANCH_UNKNOWN = 4; |
||
21 | |||
22 | /** |
||
23 | * @var string variable name |
||
24 | */ |
||
25 | protected $name; |
||
26 | |||
27 | /** |
||
28 | * @var mixed variable value |
||
29 | */ |
||
30 | protected $value; |
||
31 | |||
32 | /** |
||
33 | * @var integer|string |
||
34 | */ |
||
35 | protected $branch; |
||
36 | |||
37 | /** |
||
38 | * @var int how many times was read from the var |
||
39 | */ |
||
40 | protected $gets = 0; |
||
41 | |||
42 | /** |
||
43 | * @var int how many times was written to the var |
||
44 | */ |
||
45 | protected $sets = 0; |
||
46 | |||
47 | /** |
||
48 | * @var bool is it referenced to another var? |
||
49 | */ |
||
50 | protected $referenced = false; |
||
51 | |||
52 | /** |
||
53 | * @var Variable|null to which variable referenced? |
||
54 | */ |
||
55 | protected $referencedTo; |
||
56 | |||
57 | /** |
||
58 | * @var int variable type |
||
59 | */ |
||
60 | protected $type; |
||
61 | |||
62 | /** |
||
63 | * Creates a variable. |
||
64 | * |
||
65 | * @param string $name |
||
66 | * @param mixed $defaultValue |
||
67 | * @param int $type |
||
68 | * @param int|string $branch |
||
69 | */ |
||
70 | 423 | public function __construct($name, $defaultValue = null, $type = CompiledExpression::UNKNOWN, $branch = self::BRANCH_ROOT) |
|
82 | |||
83 | /** |
||
84 | * Increases the read counter. |
||
85 | * |
||
86 | * @return int |
||
87 | */ |
||
88 | 26 | public function incGets() |
|
92 | |||
93 | /** |
||
94 | * Increases the write counter. |
||
95 | * |
||
96 | * @return int |
||
97 | */ |
||
98 | 19 | public function incSets() |
|
102 | |||
103 | /** |
||
104 | * Gets the read counter. |
||
105 | * |
||
106 | * @return int |
||
107 | */ |
||
108 | 3 | public function getGets() |
|
112 | |||
113 | /** |
||
114 | * Gets the write counter. |
||
115 | * |
||
116 | * @return int |
||
117 | */ |
||
118 | 3 | public function getSets() |
|
122 | |||
123 | /** |
||
124 | * @return string |
||
125 | */ |
||
126 | 409 | public function getName() |
|
130 | |||
131 | /** |
||
132 | * @return mixed |
||
133 | */ |
||
134 | 18 | public function getType() |
|
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | 1 | public function getTypeName() |
|
143 | { |
||
144 | 1 | return Types::getTypeName($this->type); |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * @return mixed |
||
149 | */ |
||
150 | 19 | public function getValue() |
|
154 | |||
155 | /** |
||
156 | * Changes variable type. |
||
157 | * |
||
158 | * @param int $type |
||
159 | */ |
||
160 | 1 | public function modifyType($type) |
|
164 | |||
165 | /** |
||
166 | * Changes variable type and value. |
||
167 | * |
||
168 | * @param int $type |
||
169 | * @param mixed $value |
||
170 | */ |
||
171 | 4 | public function modify($type, $value) |
|
180 | |||
181 | /** |
||
182 | * Increment uses for gets and sets |
||
183 | */ |
||
184 | 10 | public function incUse() |
|
189 | |||
190 | /** |
||
191 | * Increment value of the variable |
||
192 | */ |
||
193 | 5 | public function inc() |
|
197 | |||
198 | /** |
||
199 | * Decrement value of the variable |
||
200 | */ |
||
201 | 5 | public function dec() |
|
205 | |||
206 | /** |
||
207 | * @return boolean |
||
208 | */ |
||
209 | 1 | public function isReferenced() |
|
213 | |||
214 | /** |
||
215 | * Is it an integer,double or number. |
||
216 | * |
||
217 | * @return bool |
||
218 | */ |
||
219 | 3 | public function isNumeric() |
|
227 | |||
228 | /** |
||
229 | * Check if you are setting values to variable but didn't use it (means get) |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | 16 | public function isUnused() |
|
237 | |||
238 | /** |
||
239 | * @return null|Variable |
||
240 | */ |
||
241 | 4 | public function getReferencedTo() |
|
245 | |||
246 | /** |
||
247 | * @param null|Variable $referencedTo |
||
248 | */ |
||
249 | 3 | public function setReferencedTo(Variable $referencedTo = null) |
|
254 | |||
255 | /** |
||
256 | * @return string |
||
257 | */ |
||
258 | 2 | public function getSymbolType() |
|
262 | |||
263 | //@codeCoverageIgnoreStart |
||
264 | /** |
||
265 | * @return array |
||
266 | */ |
||
267 | public function __debugInfo() |
||
293 | //@codeCoverageIgnoreEnd |
||
294 | } |
||
295 |