From 114ee6e4121d9a9e0fd1e50b2e01e3a9f65a61cb Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sat, 12 Oct 2019 14:49:17 +0200 Subject: [PATCH] Fix new phan errors, part 6 Bug: T231636 Change-Id: I1870b6cbeb31e54fde5e675fec51446b330e06c5 --- .../htmlform/fields/HTMLFormFieldCloner.php | 8 +++++ .../htmlform/fields/HTMLMultiSelectField.php | 1 + includes/interwiki/InterwikiLookupAdapter.php | 1 + includes/libs/DnsSrvDiscoverer.php | 2 +- includes/libs/XhprofData.php | 33 ++++++++++--------- .../filebackend/FileBackendMultiWrite.php | 3 +- .../libs/filebackend/FileBackendStore.php | 2 +- includes/libs/filebackend/FileOpBatch.php | 3 +- includes/libs/http/MultiHttpClient.php | 2 +- .../objectcache/wancache/WANObjectCache.php | 4 ++- includes/libs/rdbms/database/DBConnRef.php | 2 +- includes/libs/rdbms/database/Database.php | 1 + .../libs/rdbms/database/DatabaseMysqlBase.php | 1 + .../database/position/MySQLMasterPos.php | 2 ++ .../resultwrapper/FakeResultWrapper.php | 1 + .../virtualrest/VirtualRESTServiceClient.php | 2 +- 16 files changed, 43 insertions(+), 25 deletions(-) diff --git a/includes/htmlform/fields/HTMLFormFieldCloner.php b/includes/htmlform/fields/HTMLFormFieldCloner.php index cdbd84da2d1..92621161ecf 100644 --- a/includes/htmlform/fields/HTMLFormFieldCloner.php +++ b/includes/htmlform/fields/HTMLFormFieldCloner.php @@ -211,6 +211,10 @@ class HTMLFormFieldCloner extends HTMLFormField { return $ret; } + /** + * @inheritDoc + * @phan-param array[] $values + */ public function cancelSubmit( $values, $alldata ) { if ( isset( $values['nonjs'] ) ) { return true; @@ -231,6 +235,10 @@ class HTMLFormFieldCloner extends HTMLFormField { return parent::cancelSubmit( $values, $alldata ); } + /** + * @inheritDoc + * @phan-param array[] $values + */ public function validate( $values, $alldata ) { if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index c373f455785..a34978d17b8 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -162,6 +162,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable $optionsOouiSections ); } + '@phan-var array[] $optionsOouiSections'; $out = []; foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) { diff --git a/includes/interwiki/InterwikiLookupAdapter.php b/includes/interwiki/InterwikiLookupAdapter.php index 4f4658004a8..75054c266c8 100644 --- a/includes/interwiki/InterwikiLookupAdapter.php +++ b/includes/interwiki/InterwikiLookupAdapter.php @@ -80,6 +80,7 @@ class InterwikiLookupAdapter implements InterwikiLookup { return false; } + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable return $this->interwikiMap[$prefix]; } diff --git a/includes/libs/DnsSrvDiscoverer.php b/includes/libs/DnsSrvDiscoverer.php index ce8a2044f59..1b91a932ba8 100644 --- a/includes/libs/DnsSrvDiscoverer.php +++ b/includes/libs/DnsSrvDiscoverer.php @@ -85,7 +85,7 @@ class DnsSrvDiscoverer { /** * @param array $server - * @param array $servers + * @param array[] $servers * @return array[] */ public function removeServer( $server, array $servers ) { diff --git a/includes/libs/XhprofData.php b/includes/libs/XhprofData.php index 122b648a59d..67a02f215c8 100644 --- a/includes/libs/XhprofData.php +++ b/includes/libs/XhprofData.php @@ -42,7 +42,7 @@ class XhprofData { /** * Per-function inclusive data. - * @var array[] $inclusive + * @var array[][] $inclusive */ protected $inclusive; @@ -152,7 +152,7 @@ class XhprofData { * - max: Maximum value * - variance: Variance (spread) of the values * - * @return array[] + * @return array[][] * @see getRawData() * @see getCompleteMetrics() */ @@ -163,40 +163,40 @@ class XhprofData { $hasMu = isset( $main['mu'] ); $hasAlloc = isset( $main['alloc'] ); - $this->inclusive = []; + $inclusive = []; foreach ( $this->hieraData as $key => $stats ) { list( $parent, $child ) = self::splitKey( $key ); - if ( !isset( $this->inclusive[$child] ) ) { - $this->inclusive[$child] = [ + if ( !isset( $inclusive[$child] ) ) { + $inclusive[$child] = [ 'ct' => 0, 'wt' => new RunningStat(), ]; if ( $hasCpu ) { - $this->inclusive[$child]['cpu'] = new RunningStat(); + $inclusive[$child]['cpu'] = new RunningStat(); } if ( $hasMu ) { - $this->inclusive[$child]['mu'] = new RunningStat(); - $this->inclusive[$child]['pmu'] = new RunningStat(); + $inclusive[$child]['mu'] = new RunningStat(); + $inclusive[$child]['pmu'] = new RunningStat(); } if ( $hasAlloc ) { - $this->inclusive[$child]['alloc'] = new RunningStat(); - $this->inclusive[$child]['free'] = new RunningStat(); + $inclusive[$child]['alloc'] = new RunningStat(); + $inclusive[$child]['free'] = new RunningStat(); } } - $this->inclusive[$child]['ct'] += $stats['ct']; + $inclusive[$child]['ct'] += $stats['ct']; foreach ( $stats as $stat => $value ) { if ( $stat === 'ct' ) { continue; } - if ( !isset( $this->inclusive[$child][$stat] ) ) { + if ( !isset( $inclusive[$child][$stat] ) ) { // Ignore unknown stats continue; } for ( $i = 0; $i < $stats['ct']; $i++ ) { - $this->inclusive[$child][$stat]->addObservation( + $inclusive[$child][$stat]->addObservation( $value / $stats['ct'] ); } @@ -205,14 +205,14 @@ class XhprofData { // Convert RunningStat instances to static arrays and add // percentage stats. - foreach ( $this->inclusive as $func => $stats ) { + foreach ( $inclusive as $func => $stats ) { foreach ( $stats as $name => $value ) { if ( $value instanceof RunningStat ) { $total = $value->getMean() * $value->getCount(); $percent = ( isset( $main[$name] ) && $main[$name] ) ? 100 * $total / $main[$name] : 0; - $this->inclusive[$func][$name] = [ + $inclusive[$func][$name] = [ 'total' => $total, 'min' => $value->min, 'mean' => $value->getMean(), @@ -224,9 +224,10 @@ class XhprofData { } } - uasort( $this->inclusive, self::makeSortFunction( + uasort( $inclusive, self::makeSortFunction( $this->config['sort'], 'total' ) ); + $this->inclusive = $inclusive; } return $this->inclusive; } diff --git a/includes/libs/filebackend/FileBackendMultiWrite.php b/includes/libs/filebackend/FileBackendMultiWrite.php index cbfd76e4071..7e718cb2230 100644 --- a/includes/libs/filebackend/FileBackendMultiWrite.php +++ b/includes/libs/filebackend/FileBackendMultiWrite.php @@ -399,6 +399,7 @@ class FileBackendMultiWrite extends FileBackend { if ( $resyncMode === 'conservative' && $cloneStat && + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $cloneStat['mtime'] > $masterStat['mtime'] ) { // Do not replace files with older ones; reduces the risk of data loss @@ -527,7 +528,7 @@ class FileBackendMultiWrite extends FileBackend { } /** - * @param array $ops File operations for FileBackend::doOperations() + * @param array[] $ops File operations for FileBackend::doOperations() * @return bool Whether there are file path sources with outside lifetime/ownership */ protected function hasVolatileSources( array $ops ) { diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index ffb8793ccfc..7515b566d42 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1182,7 +1182,7 @@ abstract class FileBackendStore extends FileBackend { * The result must have the same number of items as the input. * An exception is thrown if an unsupported operation is requested. * - * @param array $ops Same format as doOperations() + * @param array[] $ops Same format as doOperations() * @return FileOp[] List of FileOp objects * @throws FileBackendError */ diff --git a/includes/libs/filebackend/FileOpBatch.php b/includes/libs/filebackend/FileOpBatch.php index bbcda085c05..58b67786624 100644 --- a/includes/libs/filebackend/FileOpBatch.php +++ b/includes/libs/filebackend/FileOpBatch.php @@ -142,13 +142,12 @@ class FileOpBatch { * within any given sub-batch do not depend on each other. * This will abort remaining ops on failure. * - * @param array $pPerformOps Batches of file ops (batches use original indexes) + * @param FileOp[][] $pPerformOps Batches of file ops (batches use original indexes) * @param StatusValue $status */ protected static function runParallelBatches( array $pPerformOps, StatusValue $status ) { $aborted = false; // set to true on unexpected errors foreach ( $pPerformOps as $performOpsBatch ) { - /** @var FileOp[] $performOpsBatch */ if ( $aborted ) { // check batch op abort flag... // We can't continue (even with $ignoreErrors) as $predicates is wrong. // Log the remaining ops as failed for recovery... diff --git a/includes/libs/http/MultiHttpClient.php b/includes/libs/http/MultiHttpClient.php index aa6a9e63b58..4ba48cd6407 100644 --- a/includes/libs/http/MultiHttpClient.php +++ b/includes/libs/http/MultiHttpClient.php @@ -158,7 +158,7 @@ class MultiHttpClient implements LoggerAwareInterface { * - reqTimeout : post-connection timeout per request (seconds) * - usePipelining : whether to use HTTP pipelining if possible (for all hosts) * - maxConnsPerHost : maximum number of concurrent connections (per host) - * @return array $reqs With response array populated for each + * @return array[] $reqs With response array populated for each * @throws Exception */ public function runMulti( array $reqs, array $opts = [] ) { diff --git a/includes/libs/objectcache/wancache/WANObjectCache.php b/includes/libs/objectcache/wancache/WANObjectCache.php index 2f44a55c6e9..fbc84d6e34d 100644 --- a/includes/libs/objectcache/wancache/WANObjectCache.php +++ b/includes/libs/objectcache/wancache/WANObjectCache.php @@ -1327,8 +1327,10 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt // Get the current key value and its metadata $curTTL = self::PASS_BY_REF; - $curInfo = self::PASS_BY_REF; /** @var array $curInfo */ + $curInfo = self::PASS_BY_REF; $curValue = $this->get( $key, $curTTL, $checkKeys, $curInfo ); + /** @var array $curInfo */ + '@phan-var array $curInfo'; // Apply any $touchedCb invalidation timestamp to get the "last purge timestamp" list( $curTTL, $LPT ) = $this->resolveCTL( $curValue, $curTTL, $curInfo, $touchedCb ); // Use the cached value if it exists and is not due for synchronous regeneration diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index 82e917998e9..1c2f46d2c80 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -31,7 +31,7 @@ class DBConnRef implements IDatabase { private $lb; /** @var Database|null Live connection handle */ private $conn; - /** @var array|null N-tuple of (server index, group, DatabaseDomain|string) */ + /** @var array N-tuple of (server index, group, DatabaseDomain|string) */ private $params; /** @var int One of DB_MASTER/DB_REPLICA */ private $role; diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 0a3b69602bf..aae04ebaabb 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -2951,6 +2951,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( !is_array( reset( $rows ) ) ) { $rows = [ $rows ]; } + '@phan-var array[] $rows'; if ( count( $uniqueIndexes ) ) { $clauses = []; // list WHERE clauses that each identify a single row diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index a95347dbc54..d816bcabc72 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -904,6 +904,7 @@ abstract class DatabaseMysqlBase extends Database { } else { // Wait on the binlog coordinates $encFile = $this->addQuotes( $pos->getLogFile() ); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $encPos = intval( $pos->getLogPosition()[$pos::CORD_EVENT] ); $sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)"; $waitPos = $pos->__toString(); diff --git a/includes/libs/rdbms/database/position/MySQLMasterPos.php b/includes/libs/rdbms/database/position/MySQLMasterPos.php index e1b8f9a2520..7030e7ec23d 100644 --- a/includes/libs/rdbms/database/position/MySQLMasterPos.php +++ b/includes/libs/rdbms/database/position/MySQLMasterPos.php @@ -178,6 +178,7 @@ class MySQLMasterPos implements DBMasterPos { * @since 1.31 */ public function getLogFile() { + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable return $this->gtids ? null : "{$this->binLog}.{$this->logPos[self::CORD_INDEX]}"; } @@ -351,6 +352,7 @@ class MySQLMasterPos implements DBMasterPos { public function __toString() { return $this->gtids ? implode( ',', $this->gtids ) + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable : $this->getLogFile() . "/{$this->logPos[self::CORD_EVENT]}"; } } diff --git a/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php b/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php index 1094fafc966..768d3c189b8 100644 --- a/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php +++ b/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php @@ -59,6 +59,7 @@ class FakeResultWrapper implements IResultWrapper { } public function current() { + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $row = $this->valid() ? $this->result[$this->pos] : false; return is_array( $row ) ? (object)$row : $row; diff --git a/includes/libs/virtualrest/VirtualRESTServiceClient.php b/includes/libs/virtualrest/VirtualRESTServiceClient.php index 96d79291697..a7f42035d6f 100644 --- a/includes/libs/virtualrest/VirtualRESTServiceClient.php +++ b/includes/libs/virtualrest/VirtualRESTServiceClient.php @@ -156,7 +156,7 @@ class VirtualRESTServiceClient { * list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $responses[0]; * @endcode * - * @param array $reqs Map of Virtual HTTP request maps + * @param array[] $reqs Map of Virtual HTTP request maps * @return array $reqs Map of corresponding response values with the same keys/order * @throws Exception */