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 | 870 | public function __construct(OutputInterface $output, Application $application, EventManager $eventManager) |
|
72 | { |
||
73 | 870 | $this->output = $output; |
|
74 | 870 | $this->application = $application; |
|
75 | |||
76 | 870 | $this->initGlobals(); |
|
77 | 870 | $this->eventManager = $eventManager; |
|
78 | 870 | } |
|
79 | |||
80 | /** |
||
81 | * @return Expression |
||
82 | */ |
||
83 | 862 | public function getExpressionCompiler() |
|
84 | { |
||
85 | 862 | return new Expression($this, $this->eventManager); |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Adds all global variables to the context. |
||
90 | */ |
||
91 | 870 | 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 | 3 | public function addSymbol($name) |
|
114 | { |
||
115 | 3 | $variable = new Variable($name); |
|
116 | 3 | $this->symbols[$name] = $variable; |
|
117 | |||
118 | 3 | return $variable; |
|
119 | 1 | } |
|
120 | |||
121 | /** |
||
122 | * Adds a variable to the context. |
||
123 | * |
||
124 | * @param Variable $variable |
||
125 | * @return bool |
||
126 | */ |
||
127 | 870 | public function addVariable(Variable $variable) |
|
128 | { |
||
129 | 870 | $this->symbols[$variable->getName()] = $variable; |
|
130 | |||
131 | 870 | return true; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Resets context to beginning stage. |
||
136 | */ |
||
137 | 43 | public function clear() |
|
147 | |||
148 | /** |
||
149 | * Clears only all symbols. |
||
150 | */ |
||
151 | 40 | public function clearSymbols() |
|
156 | |||
157 | /** |
||
158 | * Returns a variable if it exists. |
||
159 | * |
||
160 | * @param $name |
||
161 | * @return Variable|null |
||
162 | */ |
||
163 | 80 | public function getSymbol($name) |
|
164 | { |
||
165 | 80 | 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 | 10 | 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 | 43 | public function notice($type, $message, \PhpParser\NodeAbstract $expr, $status = Check::CHECK_SAFE) |
|
230 | |||
231 | /** |
||
232 | * Creates a syntax error message. |
||
233 | * |
||
234 | * @param \PhpParser\Error $exception |
||
235 | * @param string $filepath |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function syntaxError(\PhpParser\Error $exception, $filepath) |
||
262 | |||
263 | /** |
||
264 | * Returns an array of all variables. |
||
265 | * |
||
266 | * @return Variable[] |
||
267 | */ |
||
268 | 40 | public function getSymbols() |
|
272 | |||
273 | /** |
||
274 | * @param AbstractDefinition $scope |
||
275 | */ |
||
276 | 870 | public function setScope(AbstractDefinition $scope = null) |
|
280 | |||
281 | /** |
||
282 | * Creates a debug message. |
||
283 | */ |
||
284 | 43 | public function debug($message, \PhpParser\Node $expr = null) |
|
297 | |||
298 | /** |
||
299 | * @return string |
||
300 | */ |
||
301 | public function getFilepath() |
||
305 | |||
306 | /** |
||
307 | * @param string $filepath |
||
308 | */ |
||
309 | 43 | public function setFilepath($filepath) |
|
313 | |||
314 | /** |
||
315 | * @return integer |
||
316 | */ |
||
317 | 37 | public function getCurrentBranch() |
|
321 | |||
322 | /** |
||
323 | * @param int|string $currentBranch |
||
324 | */ |
||
325 | 9 | public function setCurrentBranch($currentBranch) |
|
329 | |||
330 | /** |
||
331 | * Updates all references on the given variable. |
||
332 | * |
||
333 | * @param Variable $variable |
||
334 | * @param $type |
||
335 | * @param $value |
||
336 | */ |
||
337 | 5 | public function modifyReferencedVariables(Variable $variable, $type, $value) |
|
348 | |||
349 | /** |
||
350 | * @return EventManager |
||
351 | */ |
||
352 | 808 | public function getEventManager() |
|
356 | } |
||
357 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.