Replace array_keys in foreach to use $_ as value instead
When the value of the associated array is not used, there is no need to use array_keys and create internal a copy of the array, just omit the value with $_ to tell static analyzer that the var is unused. Change-Id: I5c6d667e98c0167c0573c683f0d617bc1d4ca619
This commit is contained in:
parent
6bd00c66be
commit
1086958611
25 changed files with 28 additions and 28 deletions
|
|
@ -3824,7 +3824,7 @@ class OutputPage extends ContextSource {
|
|||
$lateVarNames =
|
||||
array_fill_keys( self::CORE_LATE_JS_CONFIG_VAR_NAMES, true ) +
|
||||
array_fill_keys( ExtensionRegistry::getInstance()->getAttribute( 'LateJSConfigVarNames' ), true );
|
||||
foreach ( array_keys( $vars ) as $name ) {
|
||||
foreach ( $vars as $name => $_ ) {
|
||||
// If the variable's late flag doesn't match the requested late flag, unset it
|
||||
if ( isset( $lateVarNames[ $name ] ) !== ( $flag === self::JS_VAR_LATE ) ) {
|
||||
unset( $vars[ $name ] );
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class Image {
|
|||
// [ "en,de,fr" => "foo.svg" ]
|
||||
// → [ "en" => "foo.svg", "de" => "foo.svg", "fr" => "foo.svg" ]
|
||||
if ( is_array( $this->descriptor ) && isset( $this->descriptor['lang'] ) ) {
|
||||
foreach ( array_keys( $this->descriptor['lang'] ) as $langList ) {
|
||||
foreach ( $this->descriptor['lang'] as $langList => $_ ) {
|
||||
if ( strpos( $langList, ',' ) !== false ) {
|
||||
$this->descriptor['lang'] += array_fill_keys(
|
||||
explode( ',', $langList ),
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class OOUIIconPackModule extends OOUIImageModule {
|
|||
|
||||
// Filter out the data for all other icons, leaving only the ones we want for this module
|
||||
$iconsNames = $this->getIcons();
|
||||
foreach ( array_keys( $definition['images'] ) as $iconName ) {
|
||||
foreach ( $definition['images'] as $iconName => $_ ) {
|
||||
if ( !in_array( $iconName, $iconsNames ) ) {
|
||||
unset( $definition['images'][$iconName] );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1084,7 +1084,7 @@ class ApiPageSet extends ApiBase {
|
|||
if ( $processTitles ) {
|
||||
// The remaining titles in $remaining are non-existent pages
|
||||
foreach ( $remaining as $ns => $dbkeys ) {
|
||||
foreach ( array_keys( $dbkeys ) as $dbkey ) {
|
||||
foreach ( $dbkeys as $dbkey => $_ ) {
|
||||
$title = $this->titleFactory->makeTitle( $ns, $dbkey );
|
||||
$this->linkCache->addBadLinkObj( $title );
|
||||
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
|
||||
|
|
|
|||
|
|
@ -998,7 +998,7 @@ class ApiParse extends ApiBase {
|
|||
private function formatIWLinks( $iw ) {
|
||||
$result = [];
|
||||
foreach ( $iw as $prefix => $titles ) {
|
||||
foreach ( array_keys( $titles ) as $title ) {
|
||||
foreach ( $titles as $title => $_ ) {
|
||||
$entry = [];
|
||||
$entry['prefix'] = $prefix;
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ class ChangesList extends ContextSource {
|
|||
public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
|
||||
$f = '';
|
||||
foreach (
|
||||
array_keys( $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) ) as $flag
|
||||
$this->getConfig()->get( MainConfigNames::RecentChangesFlags ) as $flag => $_
|
||||
) {
|
||||
$f .= isset( $flags[$flag] ) && $flags[$flag]
|
||||
? self::flag( $flag, $this->getContext() )
|
||||
|
|
|
|||
|
|
@ -4208,7 +4208,7 @@ class EditPage implements IEditObject {
|
|||
return $templates;
|
||||
}
|
||||
foreach ( $this->mParserOutput->getTemplates() as $ns => $template ) {
|
||||
foreach ( array_keys( $template ) as $dbk ) {
|
||||
foreach ( $template as $dbk => $_ ) {
|
||||
$templates[] = Title::makeTitle( $ns, $dbk );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ class LocalRepo extends FileRepo {
|
|||
|
||||
// Query image table
|
||||
$imgNames = [];
|
||||
foreach ( array_keys( $searchSet ) as $dbKey ) {
|
||||
foreach ( $searchSet as $dbKey => $_ ) {
|
||||
$imgNames[] = $this->getNameFromTitle( File::normalizeTitle( $dbKey ) );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ trait MediaFileTrait {
|
|||
'original' => null,
|
||||
];
|
||||
|
||||
foreach ( array_keys( $transforms ) as $transformType ) {
|
||||
foreach ( $transforms as $transformType => $_ ) {
|
||||
$responseFile[$transformType] = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ abstract class Installer {
|
|||
|
||||
$databases = array_flip( $databases );
|
||||
$ok = true;
|
||||
foreach ( array_keys( $databases ) as $db ) {
|
||||
foreach ( $databases as $db => $_ ) {
|
||||
$installer = $this->getDBInstaller( $db );
|
||||
$status = $installer->checkPrerequisites();
|
||||
if ( !$status->isGood() ) {
|
||||
|
|
|
|||
|
|
@ -1518,7 +1518,7 @@ class MessageCache implements LoggerAwareInterface {
|
|||
*/
|
||||
public function clear() {
|
||||
$langs = $this->languageNameUtils->getLanguageNames();
|
||||
foreach ( array_keys( $langs ) as $code ) {
|
||||
foreach ( $langs as $code => $_ ) {
|
||||
$this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
|
||||
}
|
||||
$this->cache->clear();
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class LBFactoryMulti extends LBFactory {
|
|||
$this->loadMonitorConfig = [ 'class' => LoadMonitor::class ];
|
||||
}
|
||||
|
||||
foreach ( array_keys( $this->externalLoadsByCluster ) as $cluster ) {
|
||||
foreach ( $this->externalLoadsByCluster as $cluster => $_ ) {
|
||||
if ( isset( $this->groupLoadsBySection[$cluster] ) ) {
|
||||
throw new LogicException(
|
||||
"External cluster '$cluster' has the same name as a main section/cluster"
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class LBFactorySimple extends LBFactory {
|
|||
|
||||
public function getAllExternalLBs(): array {
|
||||
$lbs = [];
|
||||
foreach ( array_keys( $this->externalServersByCluster ) as $cluster ) {
|
||||
foreach ( $this->externalServersByCluster as $cluster => $_ ) {
|
||||
$lbs[$cluster] = $this->getExternalLB( $cluster );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
|
|||
*/
|
||||
public function getNumberedArguments() {
|
||||
$arguments = [];
|
||||
foreach ( array_keys( $this->numberedArgs ) as $key ) {
|
||||
foreach ( $this->numberedArgs as $key => $_ ) {
|
||||
$arguments[$key] = $this->getArgument( $key );
|
||||
}
|
||||
return $arguments;
|
||||
|
|
@ -140,7 +140,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
|
|||
*/
|
||||
public function getNamedArguments() {
|
||||
$arguments = [];
|
||||
foreach ( array_keys( $this->namedArgs ) as $key ) {
|
||||
foreach ( $this->namedArgs as $key => $_ ) {
|
||||
$arguments[$key] = $this->getArgument( $key );
|
||||
}
|
||||
return $arguments;
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class ParserOutputSearchDataExtractor {
|
|||
$outgoingLinks = [];
|
||||
|
||||
foreach ( $parserOutput->getLinks() as $linkedNamespace => $namespaceLinks ) {
|
||||
foreach ( array_keys( $namespaceLinks ) as $linkedDbKey ) {
|
||||
foreach ( $namespaceLinks as $linkedDbKey => $_ ) {
|
||||
$outgoingLinks[] =
|
||||
Title::makeTitle( $linkedNamespace, $linkedDbKey )->getPrefixedDBkey();
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ class ParserOutputSearchDataExtractor {
|
|||
$templates = [];
|
||||
|
||||
foreach ( $parserOutput->getTemplates() as $tNS => $templatesInNS ) {
|
||||
foreach ( array_keys( $templatesInNS ) as $tDbKey ) {
|
||||
foreach ( $templatesInNS as $tDbKey => $_ ) {
|
||||
$templateTitle = Title::makeTitle( $tNS, $tDbKey );
|
||||
$templates[] = $templateTitle->getPrefixedText();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ class SpecialMovePage extends UnlistedSpecialPage {
|
|||
// mediawiki.special.movePage module
|
||||
|
||||
$immovableNamespaces = [];
|
||||
foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
|
||||
foreach ( $this->getLanguage()->getNamespaces() as $nsId => $_ ) {
|
||||
if ( !$this->nsInfo->isMovable( $nsId ) ) {
|
||||
$immovableNamespaces[] = $nsId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -425,7 +425,7 @@ class NamespaceInfo {
|
|||
public function getValidNamespaces() {
|
||||
if ( $this->validNamespaces === null ) {
|
||||
$this->validNamespaces = [];
|
||||
foreach ( array_keys( $this->getCanonicalNamespaces() ) as $ns ) {
|
||||
foreach ( $this->getCanonicalNamespaces() as $ns => $_ ) {
|
||||
if ( $ns >= 0 ) {
|
||||
$this->validNamespaces[] = $ns;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class AllTrans extends Maintenance {
|
|||
public function execute() {
|
||||
$localisationCache = MediaWikiServices::getInstance()->getLocalisationCache();
|
||||
$englishMessages = $localisationCache->getItem( 'en', 'messages' );
|
||||
foreach ( array_keys( $englishMessages ) as $key ) {
|
||||
foreach ( $englishMessages as $key => $_ ) {
|
||||
$this->output( "$key\n" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class DumpMessages extends Maintenance {
|
|||
$messages = [];
|
||||
$localisationCache = MediaWikiServices::getInstance()->getLocalisationCache();
|
||||
$localisationMessagesEn = $localisationCache->getItem( 'en', 'messages' );
|
||||
foreach ( array_keys( $localisationMessagesEn ) as $key ) {
|
||||
foreach ( $localisationMessagesEn as $key => $_ ) {
|
||||
$messages[$key] = wfMessage( $key )->text();
|
||||
}
|
||||
$this->output( "MediaWiki " . MW_VERSION . " language file\n" );
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ class BotPasswordSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
];
|
||||
$dataMD = $data['metadata'];
|
||||
|
||||
foreach ( array_keys( $data['metadata'] ) as $key ) {
|
||||
foreach ( $data['metadata'] as $key => $_ ) {
|
||||
$data['metadata'] = $dataMD;
|
||||
unset( $data['metadata'][$key] );
|
||||
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, $data );
|
||||
|
|
|
|||
|
|
@ -120,13 +120,13 @@ class SkinMustacheTest extends MediaWikiIntegrationTestCase {
|
|||
$data = $skin->getTemplateData();
|
||||
|
||||
// Validate the default template data respects the naming rules
|
||||
foreach ( array_keys( $data ) as $key ) {
|
||||
foreach ( $data as $key => $_ ) {
|
||||
$this->validateTemplateData( $data, $key );
|
||||
}
|
||||
|
||||
// Validate search data
|
||||
$searchData = $data['data-search-box'];
|
||||
foreach ( array_keys( $searchData ) as $key ) {
|
||||
foreach ( $searchData as $key => $_ ) {
|
||||
$this->validateTemplateData( $searchData, $key );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class MediaWikiIntegrationTestCaseTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
public static function provideExistingKeysAndNewValues() {
|
||||
$providedArray = [];
|
||||
foreach ( array_keys( self::$startGlobals ) as $key ) {
|
||||
foreach ( self::$startGlobals as $key => $_ ) {
|
||||
$providedArray[] = [ $key, 'newValue' ];
|
||||
$providedArray[] = [ $key, [ 'newValue' ] ];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
|
|||
$moduleManager = $this->getModuleManager();
|
||||
$moduleManager->addModules( $modules, $group );
|
||||
|
||||
foreach ( array_keys( $modules ) as $name ) {
|
||||
foreach ( $modules as $name => $_ ) {
|
||||
$this->assertTrue( $moduleManager->isDefined( $name, $group ), 'isDefined' );
|
||||
$this->assertNotNull( $moduleManager->getModule( $name, $group, true ), 'getModule' );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class MetricTest extends TestCase {
|
|||
}
|
||||
|
||||
public function handleType( $type, $format ) {
|
||||
foreach ( array_keys( self::TESTS ) as $test ) {
|
||||
foreach ( self::TESTS as $test => $_ ) {
|
||||
$this->handleTest( $test, $type, $format );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2338,7 +2338,7 @@ class WANObjectCacheTest extends MediaWikiUnitTestCase {
|
|||
|
||||
$cache->getWithSetCallback( $key, 60, $callback );
|
||||
$wrapper = TestingAccessWrapper::newFromObject( $bag );
|
||||
foreach ( array_keys( $wrapper->bag ) as $bagKey ) {
|
||||
foreach ( $wrapper->bag as $bagKey => $_ ) {
|
||||
if ( $keyNeedle === null ) {
|
||||
$this->assertDoesNotMatchRegularExpression( '/[#{}]/', $bagKey, 'Respects "coalesceKeys"' );
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue