diff --git a/includes/OutputPage.php b/includes/OutputPage.php index f389e02f514..26e058de53e 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 ] ); diff --git a/includes/ResourceLoader/Image.php b/includes/ResourceLoader/Image.php index 1e437f5a389..bf5d3d06b58 100644 --- a/includes/ResourceLoader/Image.php +++ b/includes/ResourceLoader/Image.php @@ -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 ), diff --git a/includes/ResourceLoader/OOUIIconPackModule.php b/includes/ResourceLoader/OOUIIconPackModule.php index e59e99c5cfb..a4bc4d8c50a 100644 --- a/includes/ResourceLoader/OOUIIconPackModule.php +++ b/includes/ResourceLoader/OOUIIconPackModule.php @@ -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] ); } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 89892a03807..fe228e9c80b 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -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; diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 5c4b917fe03..f715dec34ac 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -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; diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index efc9687791c..4cc791d8ac3 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -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() ) diff --git a/includes/editpage/EditPage.php b/includes/editpage/EditPage.php index a934cd5a777..997303583e3 100644 --- a/includes/editpage/EditPage.php +++ b/includes/editpage/EditPage.php @@ -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 ); } } diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 54fb86ed568..782cfe42f75 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -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 ) ); } diff --git a/includes/filerepo/file/MediaFileTrait.php b/includes/filerepo/file/MediaFileTrait.php index a9e7c81d837..e602047e51f 100644 --- a/includes/filerepo/file/MediaFileTrait.php +++ b/includes/filerepo/file/MediaFileTrait.php @@ -48,7 +48,7 @@ trait MediaFileTrait { 'original' => null, ]; - foreach ( array_keys( $transforms ) as $transformType ) { + foreach ( $transforms as $transformType => $_ ) { $responseFile[$transformType] = null; } diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 87725de8d7d..d23b61103f8 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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() ) { diff --git a/includes/language/MessageCache.php b/includes/language/MessageCache.php index bd60685733b..7ac00ef8e3b 100644 --- a/includes/language/MessageCache.php +++ b/includes/language/MessageCache.php @@ -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(); diff --git a/includes/libs/rdbms/lbfactory/LBFactoryMulti.php b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php index 31fedc696d0..d26f506a0f6 100644 --- a/includes/libs/rdbms/lbfactory/LBFactoryMulti.php +++ b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php @@ -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" diff --git a/includes/libs/rdbms/lbfactory/LBFactorySimple.php b/includes/libs/rdbms/lbfactory/LBFactorySimple.php index 5bf80afd02c..3e1be8d2601 100644 --- a/includes/libs/rdbms/lbfactory/LBFactorySimple.php +++ b/includes/libs/rdbms/lbfactory/LBFactorySimple.php @@ -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 ); } diff --git a/includes/parser/PPTemplateFrame_Hash.php b/includes/parser/PPTemplateFrame_Hash.php index 443f03da924..e5da1b1043f 100644 --- a/includes/parser/PPTemplateFrame_Hash.php +++ b/includes/parser/PPTemplateFrame_Hash.php @@ -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; diff --git a/includes/search/ParserOutputSearchDataExtractor.php b/includes/search/ParserOutputSearchDataExtractor.php index 6a508c0cd5d..fd8c5b03d19 100644 --- a/includes/search/ParserOutputSearchDataExtractor.php +++ b/includes/search/ParserOutputSearchDataExtractor.php @@ -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(); } diff --git a/includes/specials/SpecialMovePage.php b/includes/specials/SpecialMovePage.php index eeace5a92ea..0781d8f5d54 100644 --- a/includes/specials/SpecialMovePage.php +++ b/includes/specials/SpecialMovePage.php @@ -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; } diff --git a/includes/title/NamespaceInfo.php b/includes/title/NamespaceInfo.php index 0dab9c50050..14162f86137 100644 --- a/includes/title/NamespaceInfo.php +++ b/includes/title/NamespaceInfo.php @@ -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; } diff --git a/maintenance/language/alltrans.php b/maintenance/language/alltrans.php index 43891cfa38d..d377c41dd96 100644 --- a/maintenance/language/alltrans.php +++ b/maintenance/language/alltrans.php @@ -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" ); } } diff --git a/maintenance/language/dumpMessages.php b/maintenance/language/dumpMessages.php index 23877ec338c..6dfb4d4a2fa 100644 --- a/maintenance/language/dumpMessages.php +++ b/maintenance/language/dumpMessages.php @@ -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" ); diff --git a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php index dcb54ac571f..780a006f1d4 100644 --- a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php +++ b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php @@ -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 ); diff --git a/tests/phpunit/includes/skins/SkinMustacheTest.php b/tests/phpunit/includes/skins/SkinMustacheTest.php index 2da86140a95..14260418b51 100644 --- a/tests/phpunit/includes/skins/SkinMustacheTest.php +++ b/tests/phpunit/includes/skins/SkinMustacheTest.php @@ -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 ); } } diff --git a/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php b/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php index 48fb86cab55..9782649b212 100644 --- a/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php @@ -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' ] ]; } diff --git a/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php b/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php index 9ea2ab666fb..fcea2e2d201 100644 --- a/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php +++ b/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php @@ -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' ); } diff --git a/tests/phpunit/unit/includes/libs/Stats/MetricTest.php b/tests/phpunit/unit/includes/libs/Stats/MetricTest.php index 035afa397c1..dc725328c1c 100644 --- a/tests/phpunit/unit/includes/libs/Stats/MetricTest.php +++ b/tests/phpunit/unit/includes/libs/Stats/MetricTest.php @@ -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 ); } } diff --git a/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php index 6ec23021d62..110993dae6a 100644 --- a/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php @@ -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 {