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 |
||
24 | */ |
||
25 | protected $name; |
||
26 | |||
27 | /** |
||
28 | * @var mixed |
||
29 | */ |
||
30 | protected $value; |
||
31 | |||
32 | /** |
||
33 | * @var integer|string |
||
34 | */ |
||
35 | protected $branch; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $gets = 0; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $sets = 0; |
||
46 | |||
47 | /** |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $referenced = false; |
||
51 | |||
52 | /** |
||
53 | * @var Variable|null |
||
54 | */ |
||
55 | protected $referencedTo; |
||
56 | |||
57 | /** |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $type; |
||
61 | |||
62 | /** |
||
63 | * @param string $name |
||
64 | * @param mixed $defaultValue |
||
65 | * @param int $type |
||
66 | * @param int|string $branch |
||
67 | */ |
||
68 | 380 | public function __construct($name, $defaultValue = null, $type = CompiledExpression::UNKNOWN, $branch = self::BRANCH_ROOT) |
|
69 | { |
||
70 | 380 | $this->name = $name; |
|
71 | |||
72 | 380 | if (!is_null($defaultValue)) { |
|
73 | 376 | $this->sets++; |
|
74 | 376 | $this->value = $defaultValue; |
|
75 | 376 | } |
|
76 | |||
77 | 380 | $this->type = (int) $type; |
|
78 | 380 | $this->branch = $branch; |
|
79 | 380 | } |
|
80 | |||
81 | /** |
||
82 | * @return int |
||
83 | */ |
||
84 | 10 | public function incGets() |
|
88 | |||
89 | /** |
||
90 | * @return int |
||
91 | */ |
||
92 | 11 | public function incSets() |
|
96 | |||
97 | /** |
||
98 | * @return int |
||
99 | */ |
||
100 | 3 | public function getGets() |
|
104 | |||
105 | /** |
||
106 | * @return int |
||
107 | */ |
||
108 | 3 | public function getSets() |
|
112 | |||
113 | /** |
||
114 | * @return mixed |
||
115 | */ |
||
116 | 367 | public function getName() |
|
120 | |||
121 | /** |
||
122 | * @return mixed |
||
123 | */ |
||
124 | 12 | public function getType() |
|
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getTypeName() |
||
133 | { |
||
134 | return Types::getTypeName($this->type); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @return null |
||
139 | */ |
||
140 | 13 | public function getValue() |
|
144 | |||
145 | /** |
||
146 | * @param int $type |
||
147 | */ |
||
148 | 1 | public function modifyType($type) |
|
152 | |||
153 | /** |
||
154 | * @param int $type |
||
155 | * @param mixed $value |
||
156 | */ |
||
157 | 1 | public function modify($type, $value) |
|
158 | { |
||
159 | 1 | $this->type = (int) $type; |
|
160 | 1 | $this->value = $value; |
|
161 | |||
162 | 1 | if ($this->referencedTo) { |
|
163 | 1 | $this->referencedTo->modify($type, $value); |
|
164 | 1 | } |
|
165 | 1 | } |
|
166 | |||
167 | 9 | public function incUse() |
|
168 | { |
||
169 | 9 | $this->incGets(); |
|
170 | 9 | $this->incSets(); |
|
171 | 9 | } |
|
172 | |||
173 | 5 | public function inc() |
|
177 | |||
178 | 5 | public function dec() |
|
182 | |||
183 | /** |
||
184 | * @return boolean |
||
185 | */ |
||
186 | 1 | public function isReferenced() |
|
190 | |||
191 | /** |
||
192 | * @return bool |
||
193 | */ |
||
194 | 3 | public function isNumeric() |
|
195 | { |
||
196 | return ( |
||
197 | 3 | $this->type & CompiledExpression::INTEGER || |
|
198 | 2 | $this->type & CompiledExpression::DOUBLE || |
|
199 | 1 | $this->type == CompiledExpression::NUMBER |
|
200 | 3 | ); |
|
201 | } |
||
202 | |||
203 | /** |
||
204 | * Check if you are setting values to variable but didn't use it (mean get) |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | 2 | public function isUnused() |
|
212 | |||
213 | /** |
||
214 | * @return null|Variable |
||
215 | */ |
||
216 | 1 | public function getReferencedTo() |
|
220 | |||
221 | /** |
||
222 | * @param null|Variable $referencedTo |
||
223 | */ |
||
224 | 1 | public function setReferencedTo(Variable $referencedTo = null) |
|
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getSymbolType() |
||
234 | { |
||
235 | return 'variable'; |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * @return array |
||
240 | */ |
||
241 | public function __debugInfo() |
||
253 | } |
||
254 |