Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -230,6 +230,7 @@ |
231 | 231 | $this->mFunction = $token[1]; |
232 | 232 | $this->mStatus = self::IN_FUNCTION; |
233 | 233 | $this->mBraces = 0; |
| 234 | + $this->mInSwitch = 0; |
234 | 235 | $this->mFunctionGlobals = array(); |
235 | 236 | $currentToken[0] = self::FUNCTION_DEFINITION; |
236 | 237 | |
— | — | @@ -258,6 +259,9 @@ |
259 | 260 | $this->mBraces++; |
260 | 261 | } elseif ( $token == '}' ) { |
261 | 262 | $this->mBraces--; |
| 263 | + if ( $this->mInSwitch <= $this->mBraces ) |
| 264 | + $this->mInSwitch = 0; |
| 265 | + |
262 | 266 | $this->purgeGlobals(); |
263 | 267 | if ( ! $this->mBraces ) { |
264 | 268 | $this->mStatus = self::WAITING_FUNCTION; |
— | — | @@ -266,6 +270,9 @@ |
267 | 271 | } elseif ( is_array ( $token ) ) { |
268 | 272 | if ( $token[0] == T_GLOBAL ) { |
269 | 273 | $this->mStatus = self::IN_GLOBAL; |
| 274 | + if ( $this->mInSwitch ) { |
| 275 | + $this->warning( "Defining global variables inside a switch in line $token[2], function {$this->mFunction}" ); |
| 276 | + } |
270 | 277 | } elseif ( ( $token[0] == T_CURLY_OPEN ) || ( $token[0] == T_DOLLAR_OPEN_CURLY_BRACES ) ) { |
271 | 278 | // {$ and ${ and All these three end in }, so we need to open an extra brace to balance |
272 | 279 | // T_STRING_VARNAME is documented as ${a but it's the text inside the braces |
— | — | @@ -294,6 +301,9 @@ |
295 | 302 | } elseif ( $token[0] == T_FUNCTION ) { |
296 | 303 | $this->warning( "Uh? Function inside function? A lamda function?" ); |
297 | 304 | $this->error( $token ); |
| 305 | + } elseif ( $token[0] == T_SWITCH ) { |
| 306 | + if ( !$this->mInSwitch ) |
| 307 | + $this->mInSwitch = $this->mBraces; |
298 | 308 | } elseif ( ( $token[0] == T_PAAMAYIM_NEKUDOTAYIM ) && is_array( $lastMeaningfulToken ) && ( $lastMeaningfulToken[0] == T_VARIABLE ) ) { |
299 | 309 | if ( ( $lastMeaningfulToken[1] == '$self' ) || ( $lastMeaningfulToken[1] == '$parent' ) ) { |
300 | 310 | # Bug of r69904 |
— | — | @@ -351,7 +361,9 @@ |
352 | 362 | $this->warning( "Global variable {$token[1]} in line $token[2], function {$this->mFunction} does not follow coding conventions" ); |
353 | 363 | } |
354 | 364 | if ( isset( $this->mFunctionGlobals[ $token[1] ] ) ) { |
355 | | - $this->warning( $token[1] . " marked as global again in line $token[2], function {$this->mFunction}" ); |
| 365 | + if ( !$this->mInSwitch ) { |
| 366 | + $this->warning( $token[1] . " marked as global again in line $token[2], function {$this->mFunction}" ); |
| 367 | + } |
356 | 368 | } else { |
357 | 369 | $this->checkGlobalName( $token[1] ); |
358 | 370 | $this->mFunctionGlobals[ $token[1] ] = array( 0, $this->mBraces, $token[2] ); |