r77828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77827‎ | r77828 | r77829 >
Date:20:41, 5 December 2010
Author:platonides
Status:deferred
Tags:
Comment:
Detect erros such as the one fixed in r77752
Modified paths:
  • /trunk/tools/code-utils/check-vars.php (modified) (history)

Diff [purge]

Index: trunk/tools/code-utils/check-vars.php
@@ -416,13 +416,29 @@
417417
418418 $this->checkClassName( $token );
419419 $currentToken[0] = self::CLASS_NAME;
420 - } else if ( in_array( $token[0], array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) {
 420+ } elseif ( in_array( $token[0], array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) {
421421 $this->mStatus = self::IN_FUNCTION_REQUIRE;
422422 $requirePath = '';
423423 continue;
424424 }
425425 }
426426
 427+ if ( self::isMeaningfulToken( $token ) && ( $lastMeaningfulToken[0] == T_THROW ) ) {
 428+ if ( $token[0] == T_VARIABLE ) {
 429+ // Probbly rethrowing from a catch, skip
 430+ } elseif ( $token[0] == T_NEW ) {
 431+ // Correct, a new class instance
 432+ // TODO: Verify it inherits from Exception
 433+ } else {
 434+ // We only want the last interpretation, see r77752
 435+ // throw Exception; -> Exception is a constant
 436+ // throw Exception("Foo"); -> Exception() is a function
 437+ // throw new Exception("Foo"); -> Exception is a class.
 438+
 439+ $this->warning( "Not using new when throwing token {$token[1]} in line $token[2], function {$this->mFunction}" );
 440+ }
 441+ }
 442+
427443 /* Try to guess the class of the variable */
428444 if ( in_array( $token[0], array( T_OBJECT_OPERATOR, T_PAAMAYIM_NEKUDOTAYIM ) ) ) {
429445 $currentToken['base'] = $lastMeaningfulToken;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77752Followup r77748, throw NEW MWExceptionreedy00:37, 5 December 2010

Status & tagging log