1 | <?php |
||
13 | class Context |
||
14 | { |
||
15 | /** |
||
16 | * For FunctionDefinition it's null, use scopePointer |
||
17 | * |
||
18 | * @var ParentDefinition|null |
||
19 | */ |
||
20 | public $scope; |
||
21 | |||
22 | /** |
||
23 | * @var AliasManager |
||
24 | */ |
||
25 | public $aliasManager; |
||
26 | |||
27 | /** |
||
28 | * @var Application |
||
29 | */ |
||
30 | public $application; |
||
31 | |||
32 | /** |
||
33 | * @var string|integer |
||
34 | */ |
||
35 | public $currentBranch; |
||
36 | |||
37 | /** |
||
38 | * @var OutputInterface |
||
39 | */ |
||
40 | public $output; |
||
41 | |||
42 | /** |
||
43 | * @var Variable[] |
||
44 | */ |
||
45 | protected $symbols = array(); |
||
46 | |||
47 | /** |
||
48 | * @var ScopePointer|null |
||
49 | */ |
||
50 | public $scopePointer; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $filepath; |
||
56 | |||
57 | /** |
||
58 | * Construct our Context with all needed information |
||
59 | * |
||
60 | * @param OutputInterface $output |
||
61 | * @param Application $application |
||
62 | */ |
||
63 | 366 | public function __construct(OutputInterface $output, Application $application) |
|
64 | { |
||
65 | 366 | $this->output = $output; |
|
66 | 366 | $this->application = $application; |
|
67 | |||
68 | 366 | $this->initGlobals(); |
|
69 | 366 | } |
|
70 | |||
71 | 366 | public function initGlobals() |
|
72 | { |
||
73 | /** |
||
74 | * http://php.net/manual/language.variables.superglobals.php |
||
75 | */ |
||
76 | 366 | $this->addVariable(new GlobalVariable('GLOBALS', array(), CompiledExpression::ARR)); |
|
77 | 366 | $this->addVariable(new GlobalVariable('_SERVER', array(), CompiledExpression::ARR)); |
|
78 | 366 | $this->addVariable(new GlobalVariable('_GET', array(), CompiledExpression::ARR)); |
|
79 | 366 | $this->addVariable(new GlobalVariable('_POST', array(), CompiledExpression::ARR)); |
|
80 | 366 | $this->addVariable(new GlobalVariable('_FILES', array(), CompiledExpression::ARR)); |
|
81 | 366 | $this->addVariable(new GlobalVariable('_COOKIE', array(), CompiledExpression::ARR)); |
|
82 | 366 | $this->addVariable(new GlobalVariable('_SESSION', array(), CompiledExpression::ARR)); |
|
83 | 366 | $this->addVariable(new GlobalVariable('_REQUEST', array(), CompiledExpression::ARR)); |
|
84 | 366 | $this->addVariable(new GlobalVariable('_ENV', array(), CompiledExpression::ARR)); |
|
85 | 366 | } |
|
86 | |||
87 | /** |
||
88 | * @param string $name |
||
89 | * @return Variable |
||
90 | */ |
||
91 | public function addSymbol($name) |
||
92 | { |
||
93 | $variable = new Variable($name); |
||
94 | $this->symbols[$name] = $variable; |
||
95 | |||
96 | return $variable; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param Variable $variable |
||
101 | * @return bool |
||
102 | */ |
||
103 | 366 | public function addVariable(Variable $variable) |
|
104 | { |
||
105 | 366 | $this->symbols[$variable->getName()] = $variable; |
|
106 | |||
107 | 366 | return true; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * Clear prevent context |
||
112 | */ |
||
113 | public function clear() |
||
114 | { |
||
115 | $this->symbols = array(); |
||
116 | $this->scope = null; |
||
117 | |||
118 | $this->initGlobals(); |
||
119 | } |
||
120 | |||
121 | public function clearSymbols() |
||
122 | { |
||
123 | unset($this->symbols); |
||
124 | $this->symbols = array(); |
||
125 | } |
||
126 | |||
127 | public function dump() |
||
128 | { |
||
129 | /** |
||
130 | * @expected |
||
131 | */ |
||
132 | var_dump($this->symbols); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param $name |
||
137 | * @return Variable|null |
||
138 | */ |
||
139 | 8 | public function getSymbol($name) |
|
143 | |||
144 | /** |
||
145 | * @param string $type |
||
146 | * @param string $message |
||
147 | * @return bool |
||
148 | */ |
||
149 | public function warning($type, $message) |
||
150 | { |
||
157 | |||
158 | /** |
||
159 | * @param string $type |
||
160 | * @param string $message |
||
161 | * @param \PhpParser\NodeAbstract $expr |
||
162 | * @param int $status |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function notice($type, $message, \PhpParser\NodeAbstract $expr, $status = Check::CHECK_SAFE) |
||
192 | |||
193 | /** |
||
194 | * @param \PhpParser\Error $exception |
||
195 | * @param string $filepath |
||
196 | * @return bool |
||
197 | */ |
||
198 | public function sytaxError(\PhpParser\Error $exception, $filepath) |
||
213 | |||
214 | /** |
||
215 | * @return Variable[] |
||
216 | */ |
||
217 | public function getSymbols() |
||
221 | |||
222 | /** |
||
223 | * @param AbstractDefinition $scope |
||
224 | */ |
||
225 | 366 | public function setScope(AbstractDefinition $scope = null) |
|
229 | |||
230 | public function debug($message) |
||
236 | |||
237 | /** |
||
238 | * @return string |
||
239 | */ |
||
240 | public function getFilepath() |
||
244 | |||
245 | /** |
||
246 | * @param string $filepath |
||
247 | */ |
||
248 | public function setFilepath($filepath) |
||
252 | |||
253 | /** |
||
254 | * @return int|string |
||
255 | */ |
||
256 | public function getCurrentBranch() |
||
260 | |||
261 | /** |
||
262 | * @param int|string $currentBranch |
||
263 | */ |
||
264 | public function setCurrentBranch($currentBranch) |
||
268 | } |
||
269 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.