From: Erik Bernhardson Date: Wed, 18 Jan 2017 00:48:59 +0000 (-0800) Subject: Un-blacklist PhanUndeclaredVariable X-Git-Tag: 1.31.0-rc.0~4277^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=e5b8bf49420fd9f0b11d8594cd0ff4a353c513e7;p=lhc%2Fweb%2Fwiklou.git Un-blacklist PhanUndeclaredVariable Undeclared variables are a very common error type that we want to catch as often as possible. To avoid needing to refactor a variety of global level code (mostly in old-style maintenance scripts) this ignores undeclared variables in global scope. This is still a good improvement over what was happening previously. Change-Id: I50b41d571724244552074b9408abbdf6160aca59 --- diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index b9bb761b3c..7f349bce5d 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -52,6 +52,7 @@ class ApiFeedWatchlist extends ApiBase { public function execute() { $config = $this->getConfig(); $feedClasses = $config->get( 'FeedClasses' ); + $params = []; try { $params = $this->extractRequestParams(); diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index f821374064..6b38302c8f 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -637,7 +637,8 @@ class ApiUpload extends ApiBase { break; case UploadBase::HOOK_ABORTED: - $this->dieWithError( $params, 'hookaborted', [ 'details' => $verification['error'] ] ); + $msg = $verification['error'] === '' ? 'hookaborted' : $verification['error']; + $this->dieWithError( $msg, 'hookaborted', [ 'details' => $verification['error'] ] ); break; default: $this->dieWithError( 'apierror-unknownerror-nocode', 'unknown-error', diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 9dc8032634..d887a13a16 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -1421,6 +1421,7 @@ abstract class Installer { $wgAutoloadClasses += $data['autoload']; $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ? + /** @suppress PhanUndeclaredVariable $wgHooks is set by DefaultSettings */ $wgHooks['LoadExtensionSchemaUpdates'] : []; if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) { diff --git a/includes/libs/StringUtils.php b/includes/libs/StringUtils.php index 26f3c4ac61..cffb5a3945 100644 --- a/includes/libs/StringUtils.php +++ b/includes/libs/StringUtils.php @@ -168,6 +168,7 @@ class StringUtils { ) { $inputPos = 0; $outputPos = 0; + $contentPos = 0; $output = ''; $foundStart = false; $encStart = preg_quote( $startDelim, '!' ); diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index 15a5c0d78f..77d4aa993f 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -100,7 +100,7 @@ abstract class LBFactory implements ILBFactory { trigger_error( E_USER_WARNING, get_class( $e ) . ': ' . $e->getMessage() ); }; - $this->profiler = isset( $params['profiler'] ) ? $params['profiler'] : null; + $this->profiler = isset( $conf['profiler'] ) ? $conf['profiler'] : null; $this->trxProfiler = isset( $conf['trxProfiler'] ) ? $conf['trxProfiler'] : new TransactionProfiler(); @@ -111,9 +111,9 @@ abstract class LBFactory implements ILBFactory { 'ChronologyProtection' => 'true' ]; - $this->cliMode = isset( $params['cliMode'] ) ? $params['cliMode'] : PHP_SAPI === 'cli'; + $this->cliMode = isset( $conf['cliMode'] ) ? $conf['cliMode'] : PHP_SAPI === 'cli'; $this->hostname = isset( $conf['hostname'] ) ? $conf['hostname'] : gethostname(); - $this->agent = isset( $params['agent'] ) ? $params['agent'] : ''; + $this->agent = isset( $conf['agent'] ) ? $conf['agent'] : ''; $this->ticket = mt_rand(); } diff --git a/includes/libs/xmp/XMP.php b/includes/libs/xmp/XMP.php index a657a33f2c..0d171f5247 100644 --- a/includes/libs/xmp/XMP.php +++ b/includes/libs/xmp/XMP.php @@ -1086,7 +1086,7 @@ class XMPReader implements LoggerAwareInterface { } } else { array_unshift( $this->mode, self::MODE_IGNORE ); - array_unshift( $this->curItem, $elm ); + array_unshift( $this->curItem, $ns . ' ' . $tag ); return; } diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index 40da3685ab..0653725863 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -217,15 +217,17 @@ class DateFormatter { } } - return $this->formatDate( $bits, $linked ); + return $this->formatDate( $bits, $matches[0], $linked ); } /** * @param array $bits + * @param string $orig Original input string, to be returned + * on formatting failure. * @param bool $link * @return string */ - public function formatDate( $bits, $link = true ) { + private function formatDate( $bits, $orig, $link = true ) { $format = $this->targets[$this->mTarget]; if ( !$link ) { @@ -300,8 +302,9 @@ class DateFormatter { } } if ( $fail ) { - /** @todo FIXME: $matches doesn't exist here, what's expected? */ - $text = $matches[0]; + // This occurs when parsing a date with day or month outside the bounds + // of possibilities. + $text = $orig; } $isoBits = []; diff --git a/includes/specials/pagers/MergeHistoryPager.php b/includes/specials/pagers/MergeHistoryPager.php index 56229b3b76..bbf97e13cb 100644 --- a/includes/specials/pagers/MergeHistoryPager.php +++ b/includes/specials/pagers/MergeHistoryPager.php @@ -54,15 +54,17 @@ class MergeHistoryPager extends ReverseChronologicalPager { $batch = new LinkBatch(); # Give some pointers to make (last) links $this->mForm->prevId = []; + $rev_id = null; foreach ( $this->mResult as $row ) { $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) ); $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) ); - $rev_id = isset( $rev_id ) ? $rev_id : $row->rev_id; - if ( $rev_id > $row->rev_id ) { - $this->mForm->prevId[$rev_id] = $row->rev_id; - } elseif ( $rev_id < $row->rev_id ) { - $this->mForm->prevId[$row->rev_id] = $rev_id; + if ( isset( $rev_id ) ) { + if ( $rev_id > $row->rev_id ) { + $this->mForm->prevId[$rev_id] = $row->rev_id; + } elseif ( $rev_id < $row->rev_id ) { + $this->mForm->prevId[$row->rev_id] = $rev_id; + } } $rev_id = $row->rev_id; diff --git a/includes/tidy/Balancer.php b/includes/tidy/Balancer.php index 1346e1cdd0..95cbe09fe2 100644 --- a/includes/tidy/Balancer.php +++ b/includes/tidy/Balancer.php @@ -1410,6 +1410,7 @@ class BalanceActiveFormattingElements { private $noahTableStack = [ [] ]; public function __destruct() { + $next = null; for ( $node = $this->head; $node; $node = $next ) { $next = $node->nextAFE; $node->prevAFE = $node->nextAFE = $node->nextNoah = null; diff --git a/maintenance/generateJsonI18n.php b/maintenance/generateJsonI18n.php index d3041d9e8f..a84f2ae52c 100644 --- a/maintenance/generateJsonI18n.php +++ b/maintenance/generateJsonI18n.php @@ -108,6 +108,7 @@ class GenerateJsonI18n extends Maintenance { if ( !is_readable( $phpfile ) ) { $this->error( "Error reading $phpfile", 1 ); } + $messages = null; include $phpfile; $phpfileContents = file_get_contents( $phpfile ); diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index 37636c85a8..b7f07629ec 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -108,9 +108,8 @@ class RebuildTextIndex extends Maintenance { ); foreach ( $res as $s ) { + $title = Title::makeTitle( $s->page_namespace, $s->page_title ); try { - $title = Title::makeTitle( $s->page_namespace, $s->page_title ); - $rev = new Revision( $s ); $content = $rev->getContent(); diff --git a/tests/phan/config.php b/tests/phan/config.php index cef03ee013..17c1fb8631 100644 --- a/tests/phan/config.php +++ b/tests/phan/config.php @@ -203,7 +203,7 @@ return [ * with complicated cross-file globals that you have no * hope of fixing. */ - 'ignore_undeclared_variables_in_global_scope' => false, + 'ignore_undeclared_variables_in_global_scope' => true, /** * Set to true in order to attempt to detect dead @@ -339,8 +339,6 @@ return [ "PhanUndeclaredProperty", // approximate error count: 3 "PhanUndeclaredStaticMethod", - // approximate error count: 79 - "PhanUndeclaredVariable", ], /**