Filip has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/328679 )
Change subject: Fixed PHP issues found by phan
......................................................................
Fixed PHP issues found by phan
Fixed some PHP issues found by phan static code analysis
Bug: T153252
Change-Id: I18d94c03286c9d97cecc4620fa51f788c3edd446
---
M includes/api/ApiHelp.php
M includes/api/ApiParse.php
M includes/filerepo/ForeignAPIRepo.php
M includes/media/SVG.php
M includes/specials/SpecialWhatlinkshere.php
M includes/user/User.php
M maintenance/mergeMessageFileList.php
M tests/phan/config.php
8 files changed, 12 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/79/328679/1
diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php
index 9a0d3ff..21118e8 100644
--- a/includes/api/ApiHelp.php
+++ b/includes/api/ApiHelp.php
@@ -519,6 +519,7 @@
case
'submodule':
$groups[] = $name;
if (
isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) {
+
/** @var array */
$map = $settings[ApiBase::PARAM_SUBMODULE_MAP];
ksort( $map );
$submodules = [];
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 287ffb7..e4c6993 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -580,6 +580,7 @@
private function formatLangLinks( $links ) {
$result = [];
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $links as $link ) {
$entry = [];
$bits = explode( ':', $link, 2 );
diff --git a/includes/filerepo/ForeignAPIRepo.php
b/includes/filerepo/ForeignAPIRepo.php
index ca41718..74ad702 100644
--- a/includes/filerepo/ForeignAPIRepo.php
+++ b/includes/filerepo/ForeignAPIRepo.php
@@ -150,17 +150,20 @@
if ( isset( $data['query']['pages'] ) ) {
# First, get results from the query. Note we only care
whether the image exists,
# not whether it has a description page.
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $data['query']['pages'] as $p ) {
$this->mFileExists[$p['title']] = (
$p['imagerepository'] !== '' );
}
# Second, copy the results to any redirects that were
queried
if ( isset( $data['query']['redirects'] ) ) {
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $data['query']['redirects'] as $r ) {
$this->mFileExists[$r['from']] =
$this->mFileExists[$r['to']];
}
}
# Third, copy the results to any non-normalized titles
that were queried
if ( isset( $data['query']['normalized'] ) ) {
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $data['query']['normalized'] as $n ) {
$this->mFileExists[$n['from']] =
$this->mFileExists[$n['to']];
}
@@ -241,6 +244,7 @@
] );
$ret = [];
if ( isset( $results['query']['allimages'] ) ) {
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $results['query']['allimages'] as $img ) {
// 1.14 was broken, doesn't return name
attribute
if ( !isset( $img['name'] ) ) {
diff --git a/includes/media/SVG.php b/includes/media/SVG.php
index 0cea6d8..3fbf846 100644
--- a/includes/media/SVG.php
+++ b/includes/media/SVG.php
@@ -95,6 +95,7 @@
if ( $metadata ) {
$metadata = $this->unpackMetadata( $metadata );
if ( isset( $metadata['translations'] ) ) {
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $metadata['translations'] as $lang =>
$langType ) {
if ( $langType ===
SVGReader::LANG_FULL_MATCH ) {
$langList[] = $lang;
@@ -438,6 +439,7 @@
$visibleFields = $this->visibleMetadataFields();
$showMeta = false;
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $metadata as $name => $value ) {
$tag = strtolower( $name );
if ( isset( self::$metaConversion[$tag] ) ) {
@@ -537,6 +539,7 @@
return [];
}
$stdMetadata = [];
+ /** @suppress PhanTypeMismatchForeach */
foreach ( $metadata as $name => $value ) {
$tag = strtolower( $name );
if ( $tag === 'originalwidth' || $tag ===
'originalheight' ) {
diff --git a/includes/specials/SpecialWhatlinkshere.php
b/includes/specials/SpecialWhatlinkshere.php
index 439b6ab..328bec9 100644
--- a/includes/specials/SpecialWhatlinkshere.php
+++ b/includes/specials/SpecialWhatlinkshere.php
@@ -182,6 +182,7 @@
);
};
+ $plRes = $tlRes = $ilRes = [];
if ( $fetchlinks ) {
$plRes = $queryFunc( $dbr, 'pagelinks', 'pl_from' );
}
diff --git a/includes/user/User.php b/includes/user/User.php
index 663c5da..a5092c5 100644
--- a/includes/user/User.php
+++ b/includes/user/User.php
@@ -861,6 +861,7 @@
return false;
}
+ /** @var array */
static $reservedUsernames = false;
if ( !$reservedUsernames ) {
$reservedUsernames = $wgReservedUsernames;
diff --git a/maintenance/mergeMessageFileList.php
b/maintenance/mergeMessageFileList.php
index bb47631..5af97f9 100644
--- a/maintenance/mergeMessageFileList.php
+++ b/maintenance/mergeMessageFileList.php
@@ -159,6 +159,7 @@
require_once RUN_MAINTENANCE_IF_MAIN;
$queue = [];
+/** @suppress PhanTypeMismatchForeach */
foreach ( $mmfl['setupFiles'] as $fileName ) {
if ( strval( $fileName ) === '' ) {
continue;
diff --git a/tests/phan/config.php b/tests/phan/config.php
index 14ff52a..05a093f 100644
--- a/tests/phan/config.php
+++ b/tests/phan/config.php
@@ -321,8 +321,6 @@
"PhanTypeMismatchArgument",
// approximate error count: 39
"PhanTypeMismatchArgumentInternal",
- // approximate error count: 16
- "PhanTypeMismatchForeach",
// approximate error count: 63
"PhanTypeMismatchProperty",
// approximate error count: 95
--
To view, visit https://gerrit.wikimedia.org/r/328679
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I18d94c03286c9d97cecc4620fa51f788c3edd446
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Filip <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits