1 | <?php |
||
15 | class Context |
||
16 | { |
||
17 | /** |
||
18 | * For FunctionDefinition it's null, use scopePointer |
||
19 | * |
||
20 | * @var ParentDefinition|null |
||
21 | */ |
||
22 | public $scope; |
||
23 | |||
24 | /** |
||
25 | * @var AliasManager |
||
26 | */ |
||
27 | public $aliasManager; |
||
28 | |||
29 | /** |
||
30 | * @var Application |
||
31 | */ |
||
32 | public $application; |
||
33 | |||
34 | /** |
||
35 | * @var string|integer |
||
36 | */ |
||
37 | public $currentBranch; |
||
38 | |||
39 | /** |
||
40 | * @var OutputInterface |
||
41 | */ |
||
42 | public $output; |
||
43 | |||
44 | /** |
||
45 | * @var Variable[] |
||
46 | */ |
||
47 | protected $symbols = []; |
||
48 | |||
49 | /** |
||
50 | * @var ScopePointer|null |
||
51 | */ |
||
52 | public $scopePointer; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $filepath; |
||
58 | |||
59 | /** |
||
60 | * @var EventManager |
||
61 | */ |
||
62 | protected $eventManager; |
||
63 | |||
64 | /** |
||
65 | * Construct our Context with all needed information |
||
66 | * |
||
67 | * @param OutputInterface $output |
||
68 | * @param Application $application |
||
69 | * @param EventManager $eventManager |
||
70 | */ |
||
71 | 882 | public function __construct(OutputInterface $output, Application $application, EventManager $eventManager) |
|
72 | { |
||
73 | 882 | $this->output = $output; |
|
74 | 882 | $this->application = $application; |
|
75 | |||
76 | 882 | $this->initGlobals(); |
|
77 | 882 | $this->eventManager = $eventManager; |
|
78 | 882 | } |
|
79 | |||
80 | /** |
||
81 | * @return Expression |
||
82 | */ |
||
83 | 881 | public function getExpressionCompiler() |
|
84 | { |
||
85 | 881 | return new Expression($this, $this->eventManager); |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Adds all global variables to the context. |
||
90 | */ |
||
91 | 882 | public function initGlobals() |
|
106 | |||
107 | /** |
||
108 | * Creates a variable from a symbol and adds it to the context. |
||
109 | * |
||
110 | * @param string $name |
||
111 | * @return Variable |
||
112 | */ |
||
113 | public function addSymbol($name) |
||
114 | { |
||
115 | $variable = new Variable($name); |
||
116 | $this->symbols[$name] = $variable; |
||
117 | |||
118 | return $variable; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Adds a variable to the context. |
||
123 | * |
||
124 | * @param Variable $variable |
||
125 | * @return bool |
||
126 | */ |
||
127 | 882 | public function addVariable(Variable $variable) |
|
128 | { |
||
129 | 882 | $this->symbols[$variable->getName()] = $variable; |
|
130 | |||
131 | 882 | return true; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Resets context to beginning stage. |
||
136 | */ |
||
137 | 48 | public function clear() |
|
147 | |||
148 | /** |
||
149 | * Clears only all symbols. |
||
150 | */ |
||
151 | 45 | public function clearSymbols() |
|
156 | |||
157 | /** |
||
158 | * Returns a variable if it exists. |
||
159 | * |
||
160 | * @param $name |
||
161 | * @return Variable|null |
||
162 | */ |
||
163 | 88 | public function getSymbol($name) |
|
164 | { |
||
165 | 88 | return isset($this->symbols[$name]) ? $this->symbols[$name] : null; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * Creates a warning message. |
||
170 | * |
||
171 | * @param string $type |
||
172 | * @param string $message |
||
173 | * @return bool |
||
174 | */ |
||
175 | 13 | public function warning($type, $message) |
|
184 | |||
185 | /** |
||
186 | * Creates a notice message. |
||
187 | * |
||
188 | * @param string $type |
||
189 | * @param string $message |
||
190 | * @param \PhpParser\NodeAbstract $expr |
||
191 | * @param int $status |
||
192 | * @return bool |
||
193 | */ |
||
194 | 48 | public function notice($type, $message, \PhpParser\NodeAbstract $expr, $status = Check::CHECK_SAFE) |
|
236 | |||
237 | /** |
||
238 | * Creates a syntax error message. |
||
239 | * |
||
240 | * @param \PhpParser\Error $exception |
||
241 | * @param string $filepath |
||
242 | * @return bool |
||
243 | */ |
||
244 | public function syntaxError(\PhpParser\Error $exception, $filepath) |
||
268 | |||
269 | /** |
||
270 | * Returns an array of all variables. |
||
271 | * |
||
272 | * @return Variable[] |
||
273 | */ |
||
274 | 45 | public function getSymbols() |
|
278 | |||
279 | /** |
||
280 | * @param AbstractDefinition $scope |
||
281 | */ |
||
282 | 882 | public function setScope(AbstractDefinition $scope = null) |
|
286 | |||
287 | /** |
||
288 | * Creates a debug message. |
||
289 | */ |
||
290 | 50 | public function debug($message, \PhpParser\Node $expr = null) |
|
303 | |||
304 | /** |
||
305 | * @return string |
||
306 | */ |
||
307 | public function getFilepath() |
||
311 | |||
312 | /** |
||
313 | * @param string $filepath |
||
314 | */ |
||
315 | 48 | public function setFilepath($filepath) |
|
319 | |||
320 | /** |
||
321 | * @return integer |
||
322 | */ |
||
323 | 41 | public function getCurrentBranch() |
|
327 | |||
328 | /** |
||
329 | * @param int|string $currentBranch |
||
330 | */ |
||
331 | 10 | public function setCurrentBranch($currentBranch) |
|
335 | |||
336 | /** |
||
337 | * Updates all references on the given variable. |
||
338 | * |
||
339 | * @param Variable $variable |
||
340 | * @param $type |
||
341 | * @param $value |
||
342 | */ |
||
343 | 6 | public function modifyReferencedVariables(Variable $variable, $type, $value) |
|
354 | |||
355 | /** |
||
356 | * @return EventManager |
||
357 | */ |
||
358 | 61 | public function getEventManager() |
|
362 | } |
||
363 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.