r106388 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106387‎ | r106388 | r106389 >
Date:22:41, 15 December 2011
Author:platonides
Status:deferred (Comments)
Tags:tools 
Comment:
Learn variable typing from function hints
Modified paths:
  • /trunk/tools/code-utils/check-vars.php (modified) (history)

Diff [purge]

Index: trunk/tools/code-utils/check-vars.php
@@ -434,6 +434,7 @@
435435 $this->mInProfilingFunction = false;
436436 $this->mAfterProfileOut = 0;
437437 $this->mFunctionGlobals = array();
 438+ $this->mLocalVariableTypes = array();
438439 $currentToken[0] = self::FUNCTION_DEFINITION;
439440 $this->mKnownFunctions[] = $this->mClass ? $this->mClass . "::" . $this->mFunction : $this->mFunction;
440441
@@ -513,6 +514,8 @@
514515
515516 if ( $lastMeaningfulToken[0] == T_PAAMAYIM_NEKUDOTAYIM ) {
516517 /* Class variable. No check for now */
 518+ } elseif ( $lastMeaningfulToken[0] == T_STRING ) {
 519+ $this->mLocalVariableTypes[ $token[1] ] = $lastMeaningfulToken[0];
517520 } else {
518521 if ( isset( $this->mFunctionGlobals[ $token[1] ] ) ) {
519522 $this->mFunctionGlobals[ $token[1] ][0] ++;
@@ -885,6 +888,10 @@
886889 }
887890 if ( $token[1] == '$this' )
888891 return $this->mClass;
 892+
 893+ if ( isset( $this->mLocalVariableTypes[$token[1]] ) )
 894+ return $this->mLocalVariableTypes[$token[1]];
 895+
889896 $name = substr( $token[1], 1 );
890897 } elseif ( ( $token[0] == T_STRING ) || ( $token[0] == self::CLASS_MEMBER ) ) {
891898 if ( ( $token[1] == 'self' ) && !isset( $token['base'] ) )

Comments

#Comment by Nikerabbit (talk | contribs)   07:27, 16 December 2011

What does this do?

#Comment by Platonides (talk | contribs)   19:05, 16 December 2011

Take argument hints, such as those added in r106389, then it knows that $a and $b are of type profile_point, and thus not warn that $a->name() might be calling the deprecated SpecialPage::name

Status & tagging log