1 | <?php |
||
37 | abstract class AbstractLocalVariable extends AbstractRule |
||
38 | { |
||
39 | /** |
||
40 | * @var array Self reference class names. |
||
41 | */ |
||
42 | protected $selfReferences = array('self', 'static'); |
||
43 | |||
44 | /** |
||
45 | * PHP super globals that are available in all php scopes, so that they |
||
46 | * can never be unused local variables. |
||
47 | * |
||
48 | * @var array(string=>boolean) |
||
49 | * @link http://php.net/manual/en/reserved.variables.php |
||
50 | */ |
||
51 | protected static $superGlobals = array( |
||
52 | '$argc' => true, |
||
53 | '$argv' => true, |
||
54 | '$_COOKIE' => true, |
||
55 | '$_ENV' => true, |
||
56 | '$_FILES' => true, |
||
57 | '$_GET' => true, |
||
58 | '$_POST' => true, |
||
59 | '$_REQUEST' => true, |
||
60 | '$_SERVER' => true, |
||
61 | '$_SESSION' => true, |
||
62 | 43 | '$GLOBALS' => true, |
|
63 | '$HTTP_RAW_POST_DATA' => true, |
||
64 | 43 | '$php_errormsg' => true, |
|
65 | 43 | '$http_response_header' => true, |
|
66 | 43 | ); |
|
67 | |||
68 | /** |
||
69 | * Tests if the given variable node represents a local variable or if it is |
||
70 | * a static object property or something similar. |
||
71 | * |
||
72 | * @param \PHPMD\Node\ASTNode $variable The variable to check. |
||
73 | * @return boolean |
||
74 | */ |
||
75 | protected function isLocal(ASTNode $variable) |
||
82 | |||
83 | /** |
||
84 | * Tests if the given variable represents one of the PHP super globals |
||
85 | * that are available in scopes. |
||
86 | * |
||
87 | * @param \PHPMD\AbstractNode $variable |
||
88 | * @return boolean |
||
89 | 43 | */ |
|
90 | protected function isSuperGlobal(AbstractNode $variable) |
||
94 | 43 | ||
95 | 17 | /** |
|
96 | 17 | * Tests if the given variable does not represent one of the PHP super globals |
|
97 | 1 | * that are available in scopes. |
|
98 | * |
||
99 | 16 | * @param \PHPMD\AbstractNode $variable |
|
100 | 16 | * @return boolean |
|
101 | */ |
||
102 | protected function isNotSuperGlobal(AbstractNode $variable) |
||
106 | |||
107 | /** |
||
108 | * Tests if the given variable node is a regular variable an not property |
||
109 | * or method postfix. |
||
110 | * |
||
111 | * @param \PHPMD\Node\ASTNode $variable |
||
112 | * @return boolean |
||
113 | 43 | */ |
|
114 | protected function isRegularVariable(ASTNode $variable) |
||
132 | 43 | ||
133 | /** |
||
134 | 43 | * Removes all index expressions that are wrapped around the given node |
|
135 | 43 | * instance. |
|
136 | * |
||
137 | * @param \PHPMD\Node\ASTNode $node |
||
138 | * @return \PHPMD\Node\ASTNode |
||
139 | */ |
||
140 | protected function stripWrappedIndexExpression(ASTNode $node) |
||
153 | |||
154 | /** |
||
155 | * Tests if the given variable node os part of an index expression. |
||
156 | * |
||
157 | * @param \PHPMD\Node\ASTNode $node |
||
158 | * @return boolean |
||
159 | */ |
||
160 | 12 | protected function isWrappedByIndexExpression(ASTNode $node) |
|
166 | |||
167 | /** |
||
168 | * PHP is case insensitive so we should compare function names case |
||
169 | * insensitive. |
||
170 | * |
||
171 | * @param \PHPMD\AbstractNode $node |
||
172 | * @param string $name |
||
173 | * @return boolean |
||
174 | */ |
||
175 | protected function isFunctionNameEqual(AbstractNode $node, $name) |
||
179 | |||
180 | /** |
||
181 | * AST puts namespace prefix to global functions called from a namespace. |
||
182 | * This method checks if the last part of function fully qualified name is equal to $name |
||
183 | * |
||
184 | * @param \PHPMD\AbstractNode $node |
||
185 | * @param string $name |
||
186 | * @return boolean |
||
187 | */ |
||
188 | protected function isFunctionNameEndingWith(AbstractNode $node, $name) |
||
194 | |||
195 | /** |
||
196 | * Get the image of the given variable node. |
||
197 | * |
||
198 | * Prefix self:: and static:: properties with "::". |
||
199 | * |
||
200 | * @param ASTVariable|ASTPropertyPostfix|ASTVariableDeclarator $variable |
||
201 | * @return string |
||
202 | */ |
||
203 | protected function getVariableImage($variable) |
||
234 | |||
235 | /** |
||
236 | * Return the PDepend node of ASTNode PHPMD node. |
||
237 | * |
||
238 | * Or return the input as is if it's not an ASTNode PHPMD node. |
||
239 | * |
||
240 | * @param mixed $node |
||
241 | * @return \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode |
||
242 | */ |
||
243 | protected function getNode($node) |
||
251 | |||
252 | /** |
||
253 | * Return true if the given variable is passed by reference in a native PHP function. |
||
254 | * |
||
255 | * @param ASTVariable|ASTPropertyPostfix|ASTVariableDeclarator $variable |
||
256 | * @return bool |
||
257 | */ |
||
258 | protected function isPassedByReference($variable) |
||
282 | } |
||
283 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: