From b9e4475985b04255c18953fd0a0cd094e1a70b11 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Wed, 9 Oct 2019 12:37:38 +0200 Subject: [PATCH] build: Upgrade mediawiki-phan-config to 0.8.0 This is to verify that our CI is able to handle the new version. Bug: T235049 Change-Id: Ib7427e15f673a575738489476e604c387f449ddd --- composer.json | 2 +- includes/AbuseFilter.php | 6 ++++-- includes/AbuseFilterRunner.php | 7 +++---- includes/Views/AbuseFilterViewDiff.php | 14 ++++++++------ includes/Views/AbuseFilterViewEdit.php | 15 ++++++--------- includes/Views/AbuseFilterViewRevert.php | 2 +- includes/parser/AFPData.php | 2 +- includes/parser/AFPTreeParser.php | 1 + includes/parser/AbuseFilterParser.php | 1 + 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index b15ef8bfc..181643b5c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "mediawiki/mediawiki-codesniffer": "26.0.0", "jakub-onderka/php-console-highlighter": "0.3.2", "mediawiki/minus-x": "0.3.2", - "mediawiki/mediawiki-phan-config": "0.7.1" + "mediawiki/mediawiki-phan-config": "0.8.0" }, "scripts": { "fix": [ diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index 30f7c57bc..81ea470d0 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -584,7 +584,8 @@ class AbuseFilter { /** * @param string[] $filters - * @return array[][] + * @return (string|array)[][][] + * @phan-return array> */ public static function getConsequencesForFilters( $filters ) { $globalFilters = []; @@ -624,7 +625,8 @@ class AbuseFilter { * @param IDatabase $dbr * @param string[] $filters * @param string $prefix - * @return array[][] + * @return (string|array)[][][] + * @phan-return array> */ public static function loadConsequencesFromDB( IDatabase $dbr, $filters, $prefix = '' ) { $actionsByFilter = []; diff --git a/includes/AbuseFilterRunner.php b/includes/AbuseFilterRunner.php index 1d1f6d623..f5e9cfc02 100644 --- a/includes/AbuseFilterRunner.php +++ b/includes/AbuseFilterRunner.php @@ -34,10 +34,8 @@ class AbuseFilterRunner { /** * @var array Data from per-filter profiling. Shape: - * - * [ - * filterID => [ 'time' => timeTaken, 'conds' => condsUsed, 'result' => result ] - * ] + * [ filterName => [ 'time' => float, 'conds' => int, 'result' => bool ] ] + * @phan-var array * * Where 'timeTaken' is in seconds, 'result' is a boolean indicating whether the filter matched * the action, and 'filterID' is "{prefix}-{ID}" ; Prefix should be empty for local @@ -465,6 +463,7 @@ class AbuseFilterRunner { * Record per-filter profiling, for all filters * * @param array $data Profiling data, as stored in $this->profilingData + * @phan-param array $data */ protected function recordPerFilterProfiling( array $data ) { global $wgAbuseFilterSlowFilterRuntimeLimit; diff --git a/includes/Views/AbuseFilterViewDiff.php b/includes/Views/AbuseFilterViewDiff.php index 9dc50b103..42b81ec61 100644 --- a/includes/Views/AbuseFilterViewDiff.php +++ b/includes/Views/AbuseFilterViewDiff.php @@ -1,12 +1,14 @@ mOldVersion = $this->loadSpec( $oldSpec, $newSpec ); $this->mNewVersion = $this->loadSpec( $newSpec, $oldSpec ); - if ( is_null( $this->mOldVersion ) || is_null( $this->mNewVersion ) ) { + if ( $this->mOldVersion === null || $this->mNewVersion === null ) { $this->getOutput()->addWikiMsg( 'abusefilter-diff-invalid' ); return false; } @@ -151,7 +153,7 @@ class AbuseFilterViewDiff extends AbuseFilterView { /** * @param string $spec * @param string $otherSpec - * @return array|null + * @return (string|array)[]|null */ public function loadSpec( $spec, $otherSpec ) { static $dependentSpecs = [ 'prev', 'next' ]; @@ -229,7 +231,7 @@ class AbuseFilterViewDiff extends AbuseFilterView { /** * @param stdClass $row - * @return array + * @return (string|array)[] */ public function loadFromHistoryRow( $row ) { return [ diff --git a/includes/Views/AbuseFilterViewEdit.php b/includes/Views/AbuseFilterViewEdit.php index 4ccd113fb..de7f9081e 100644 --- a/includes/Views/AbuseFilterViewEdit.php +++ b/includes/Views/AbuseFilterViewEdit.php @@ -479,9 +479,10 @@ class AbuseFilterViewEdit extends AbuseFilterView { $output = ''; foreach ( $enabledActions as $action => $_ ) { - $params = $actions[$action] ?? null; - $output .= $this->buildConsequenceSelector( - $action, $setActions[$action], $row, $params ); + if ( array_key_exists( $action, $actions ) ) { + $output .= $this->buildConsequenceSelector( + $action, $setActions[$action], $row, $actions[$action] ); + } } return $output; @@ -491,16 +492,12 @@ class AbuseFilterViewEdit extends AbuseFilterView { * @param string $action The action to build an editor for * @param bool $set Whether or not the action is activated * @param stdClass $row abuse_filter row object - * @param array|null $parameters Action parameters + * @param array $parameters Action parameters * @return string|\OOUI\FieldLayout */ - private function buildConsequenceSelector( $action, $set, $row, array $parameters = null ) { + private function buildConsequenceSelector( $action, $set, $row, array $parameters ) { $config = $this->getConfig(); $user = $this->getUser(); - $actions = $config->get( 'AbuseFilterActions' ); - if ( empty( $actions[$action] ) ) { - return ''; - } $readOnly = !AbuseFilter::canEditFilter( $user, $row ); diff --git a/includes/Views/AbuseFilterViewRevert.php b/includes/Views/AbuseFilterViewRevert.php index 30ed24cbc..2d54bd106 100644 --- a/includes/Views/AbuseFilterViewRevert.php +++ b/includes/Views/AbuseFilterViewRevert.php @@ -171,7 +171,7 @@ class AbuseFilterViewRevert extends AbuseFilterView { } /** - * @return array + * @return array[] */ public function doLookup() { $periodStart = $this->mPeriodStart; diff --git a/includes/parser/AFPData.php b/includes/parser/AFPData.php index db3ae3a57..3875eb589 100644 --- a/includes/parser/AFPData.php +++ b/includes/parser/AFPData.php @@ -123,7 +123,7 @@ class AFPData { } elseif ( $target === self::DFLOAT ) { return new AFPData( self::DFLOAT, floatval( count( $orig->data ) ) ); } elseif ( $target === self::DINT ) { - return new AFPData( self::DINT, intval( count( $orig->data ) ) ); + return new AFPData( self::DINT, count( $orig->data ) ); } elseif ( $target === self::DSTRING ) { $s = ''; foreach ( $orig->data as $item ) { diff --git a/includes/parser/AFPTreeParser.php b/includes/parser/AFPTreeParser.php index 7f03140c9..e9cf89a22 100644 --- a/includes/parser/AFPTreeParser.php +++ b/includes/parser/AFPTreeParser.php @@ -5,6 +5,7 @@ * evaluating it into different passes, allowing the parse tree to be cached. * * @file + * @phan-file-suppress PhanPossiblyInfiniteRecursionSameParams Recursion controlled by class props */ use Psr\Log\LoggerInterface; diff --git a/includes/parser/AbuseFilterParser.php b/includes/parser/AbuseFilterParser.php index 93b5c982a..c5222647d 100644 --- a/includes/parser/AbuseFilterParser.php +++ b/includes/parser/AbuseFilterParser.php @@ -906,6 +906,7 @@ class AbuseFilterParser { throw new AFPUserVisibleException( 'outofbounds', $this->mCur->pos, [ $idx, count( $result->getData() ) ] ); } + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable Guaranteed to be array $result = $result->getData()[$idx]; } elseif ( $result->getType() === AFPData::DUNDEFINED ) { $result = new AFPData( AFPData::DUNDEFINED );