r70958 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70957‎ | r70958 | r70959 >
Date:14:29, 12 August 2010
Author:platonides
Status:deferred
Tags:
Comment:
Do not complain about duplicates if they appear inside switches.
Show a warning in such case since the script would not detect a variable needing a global after a break.

Reported in http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69898#c8149
Modified paths:
  • /trunk/tools/code-utils/check-vars.php (modified) (history)

Diff [purge]

Index: trunk/tools/code-utils/check-vars.php
@@ -230,6 +230,7 @@
231231 $this->mFunction = $token[1];
232232 $this->mStatus = self::IN_FUNCTION;
233233 $this->mBraces = 0;
 234+ $this->mInSwitch = 0;
234235 $this->mFunctionGlobals = array();
235236 $currentToken[0] = self::FUNCTION_DEFINITION;
236237
@@ -258,6 +259,9 @@
259260 $this->mBraces++;
260261 } elseif ( $token == '}' ) {
261262 $this->mBraces--;
 263+ if ( $this->mInSwitch <= $this->mBraces )
 264+ $this->mInSwitch = 0;
 265+
262266 $this->purgeGlobals();
263267 if ( ! $this->mBraces ) {
264268 $this->mStatus = self::WAITING_FUNCTION;
@@ -266,6 +270,9 @@
267271 } elseif ( is_array ( $token ) ) {
268272 if ( $token[0] == T_GLOBAL ) {
269273 $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+ }
270277 } elseif ( ( $token[0] == T_CURLY_OPEN ) || ( $token[0] == T_DOLLAR_OPEN_CURLY_BRACES ) ) {
271278 // {$ and ${ and All these three end in }, so we need to open an extra brace to balance
272279 // T_STRING_VARNAME is documented as ${a but it's the text inside the braces
@@ -294,6 +301,9 @@
295302 } elseif ( $token[0] == T_FUNCTION ) {
296303 $this->warning( "Uh? Function inside function? A lamda function?" );
297304 $this->error( $token );
 305+ } elseif ( $token[0] == T_SWITCH ) {
 306+ if ( !$this->mInSwitch )
 307+ $this->mInSwitch = $this->mBraces;
298308 } elseif ( ( $token[0] == T_PAAMAYIM_NEKUDOTAYIM ) && is_array( $lastMeaningfulToken ) && ( $lastMeaningfulToken[0] == T_VARIABLE ) ) {
299309 if ( ( $lastMeaningfulToken[1] == '$self' ) || ( $lastMeaningfulToken[1] == '$parent' ) ) {
300310 # Bug of r69904
@@ -351,7 +361,9 @@
352362 $this->warning( "Global variable {$token[1]} in line $token[2], function {$this->mFunction} does not follow coding conventions" );
353363 }
354364 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+ }
356368 } else {
357369 $this->checkGlobalName( $token[1] );
358370 $this->mFunctionGlobals[ $token[1] ] = array( 0, $this->mBraces, $token[2] );

Status & tagging log