From 832f6a16836d8fc0d8043eb0aa6bc7b6f579ba63 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 3 Jan 2025 10:31:48 +1000
Subject: [PATCH] Issue #3477156 by quietone, mstrelan, alexpott: Use
 DrupalPractice.CodeAnalysis.VariableAnalysis on Functional* tests

---
 .../big_pipe/tests/src/Functional/BigPipeTest.php  |  2 +-
 .../block/tests/src/Functional/BlockTest.php       |  2 +-
 .../CKEditor5ReadOnlyModeTest.php                  |  1 -
 .../tests/src/FunctionalJavascript/MediaTest.php   |  2 +-
 .../Functional/ConfigTranslationOverviewTest.php   |  4 ++--
 .../tests/src/Functional/ModerationLocaleTest.php  |  6 +++---
 .../Functional/ModerationStateTaxonomyTermTest.php |  2 +-
 .../Functional/ContentTranslationLinkTagTest.php   |  4 ++--
 .../Functional/ContentTranslationUITestBase.php    |  2 +-
 .../src/FunctionalJavascript/EditorAdminTest.php   |  1 -
 .../tests/src/Functional/FileFieldWidgetTest.php   |  3 +--
 .../tests/src/Functional/InternalEntitiesTest.php  |  2 +-
 .../tests/src/Functional/ResourceTestBase.php      |  4 ++--
 .../tests/src/Functional/LanguageSwitchingTest.php |  7 -------
 .../src/FunctionalJavascript/AjaxBlockTest.php     |  3 +--
 .../FunctionalJavascript/WidgetOverflowTest.php    |  1 -
 .../src/FunctionalJavascript/WidgetUploadTest.php  |  4 ++--
 .../node/tests/src/Functional/PagePreviewTest.php  |  2 +-
 .../Functional/FailureMarkerRequirementTest.php    |  1 +
 .../rest/tests/src/Functional/ResourceTest.php     |  4 ++--
 .../rest/tests/src/Functional/ResourceTestBase.php |  2 +-
 .../src/Functional/Views/StyleSerializerTest.php   |  2 +-
 .../tests/src/Functional/Ajax/FrameworkTest.php    |  1 -
 .../DrupalKernel/ContentNegotiationTest.php        |  2 +-
 .../Functional/Form/ElementsTableSelectTest.php    | 14 ++++++--------
 .../tests/src/Functional/Routing/RouterTest.php    |  1 -
 .../System/DefaultMobileMetaTagsTest.php           |  4 ++--
 .../tests/src/Functional/Theme/ThemeUiTest.php     |  2 +-
 .../src/Functional/TaxonomyTermIndentationTest.php |  4 ++--
 .../taxonomy/tests/src/Functional/TermTest.php     |  4 ----
 .../Functional/Views/TaxonomyFieldAllTermsTest.php |  1 -
 .../tests/src/Functional/VocabularyUiTest.php      |  2 +-
 .../Views/UserFieldsAccessChangeTest.php           |  5 -----
 .../views/tests/src/Functional/BulkFormTest.php    |  2 +-
 .../tests/src/Functional/Plugin/PagerTest.php      |  4 ++--
 .../views_ui/tests/src/Functional/DisplayTest.php  |  2 +-
 .../Functional/FilterEntityReferenceWebTest.php    |  2 +-
 .../views_ui/tests/src/Functional/HandlerTest.php  |  2 +-
 core/phpcs.xml.dist                                |  3 +--
 .../StandardPerformanceTest.php                    |  4 ++--
 .../tests/src/Traits/StandardTestTrait.php         |  1 -
 41 files changed, 47 insertions(+), 74 deletions(-)

diff --git a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
index 4229bde51852..1fac58c81152 100644
--- a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
+++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
@@ -475,7 +475,7 @@ protected function getTestCases($has_session = TRUE) {
    * @internal
    */
   protected function assertSetsEqual(array $a, array $b): void {
-    $result = count($a) == count($b) && !array_diff_assoc($a, $b);
+    count($a) == count($b) && !array_diff_assoc($a, $b);
   }
 
   /**
diff --git a/core/modules/block/tests/src/Functional/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php
index 5b99aa839bd2..11a0ae457ca0 100644
--- a/core/modules/block/tests/src/Functional/BlockTest.php
+++ b/core/modules/block/tests/src/Functional/BlockTest.php
@@ -183,7 +183,7 @@ public function testAddBlockFromLibraryWithWeight(): void {
       $this->assertSession()->elementTextEquals('xpath', $xpath, 'Place block');
 
       $link = $this->getSession()->getPage()->find('xpath', $xpath);
-      [$path, $query_string] = explode('?', $link->getAttribute('href'), 2);
+      [, $query_string] = explode('?', $link->getAttribute('href'), 2);
       parse_str($query_string, $query_parts);
       $this->assertEquals($weight, $query_parts['weight'], 'Found the expected weight query string.');
 
diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php
index fd62a633aad4..c52ae83c9118 100644
--- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php
+++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php
@@ -53,7 +53,6 @@ protected function setUp(): void {
    * Test that disabling a CKEditor 5 field results in an uneditable editor.
    */
   public function testReadOnlyMode(): void {
-    $page = $this->getSession()->getPage();
     $assert_session = $this->assertSession();
     $this->addNewTextFormat();
 
diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php
index 92a3c3d2feec..368fcc422e3b 100644
--- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php
+++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php
@@ -595,7 +595,7 @@ protected function testAlignment(): void {
     // Ensure that by default the "Break text" alignment option is selected.
     $this->click('.ck-widget.drupal-media');
     $this->assertVisibleBalloon('[aria-label="Drupal Media toolbar"]');
-    $this->assertTrue(($align_button = $this->getBalloonButton('Break text'))->hasClass('ck-on'));
+    $this->assertTrue($this->getBalloonButton('Break text')->hasClass('ck-on'));
     $editor_dom = $this->getEditorDataAsDom();
     $drupal_media_element = $editor_dom->getElementsByTagName('drupal-media')
       ->item(0);
diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationOverviewTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationOverviewTest.php
index 7a7ca6ba12f4..35356783fde0 100644
--- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationOverviewTest.php
+++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationOverviewTest.php
@@ -89,7 +89,7 @@ public function testMapperListPage(): void {
     $this->assertSession()->linkByHrefExists('admin/config/people/accounts/translate');
     // Make sure there is only a single operation for each dropbutton, either
     // 'List' or 'Translate'.
-    foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
+    foreach ($this->cssSelect('ul.dropbutton') as $dropbutton) {
       $this->assertCount(1, $dropbutton->findAll('xpath', 'li'));
       $this->assertTrue(($dropbutton->getText() === 'Translate') || ($dropbutton->getText() === 'List'));
     }
@@ -115,7 +115,7 @@ public function testMapperListPage(): void {
 
       // Make sure there is only a single 'Translate' operation for each
       // dropbutton.
-      foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
+      foreach ($this->cssSelect('ul.dropbutton') as $dropbutton) {
         $this->assertCount(1, $dropbutton->findAll('xpath', 'li'));
         $this->assertSame('Translate', $dropbutton->getText());
       }
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
index a3b8abe12361..14bdf3ed44df 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
@@ -351,11 +351,11 @@ public function testLanguageIndependentContentModeration(): void {
     foreach (range(11, 16) as $revision_id) {
       /** @var \Drupal\node\NodeInterface $revision */
       $revision = $storage->loadRevision($revision_id);
-      foreach ($revision->getTranslationLanguages() as $langcode => $language) {
+      foreach (array_keys($revision->getTranslationLanguages()) as $langcode) {
         if ($revision->isRevisionTranslationAffected()) {
-          $this->drupalGet($revision->toUrl('revision'));
+          $translation = $revision->getTranslation($langcode);
+          $this->drupalGet($translation->toUrl('revision'));
           $this->assertFalse($this->hasModerationForm(), 'Moderation form is not displayed correctly for revision ' . $revision_id);
-          break;
         }
       }
     }
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationStateTaxonomyTermTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateTaxonomyTermTest.php
index 7b796f6242a9..f71974249c46 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationStateTaxonomyTermTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateTaxonomyTermTest.php
@@ -27,7 +27,7 @@ protected function setUp(): void {
     parent::setUp();
 
     // Create a "Tags" vocabulary.
-    $bundle = Vocabulary::create([
+    Vocabulary::create([
       'vid' => 'tags',
       'name' => 'Tags',
       'new_revision' => FALSE,
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php
index 80fdd9a7188d..64ff8e16da09 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php
@@ -116,7 +116,7 @@ function ($langcode) use ($url_base, $languageManager) {
 
     // Ensure link tags for all languages are found on each language variation
     // page of an entity.
-    foreach ($urls as $langcode => $url) {
+    foreach ($urls as $url) {
       $this->drupalGet($url);
       foreach ($urls as $langcode_alternate => $url_alternate) {
         $this->assertSession()->elementAttributeContains('xpath', "head/link[@rel='alternate' and @hreflang='$langcode_alternate']", 'href', $url_alternate->toString());
@@ -128,7 +128,7 @@ function ($langcode) use ($url_base, $languageManager) {
     $this->config('system.site')->set('page.front', $entity_canonical)->save();
 
     // Tests hreflang when using entities as a front page.
-    foreach ($urls as $langcode => $url) {
+    foreach ($urls as $url) {
       $this->drupalGet($url);
       foreach ($entity->getTranslationLanguages() as $language) {
         $frontpage_path = Url::fromRoute('<front>', [], [
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
index 75aaec084a8a..6afba2496d46 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
@@ -325,7 +325,7 @@ protected function doTestAuthoringInfo() {
     $values = [];
 
     // Post different authoring information for each translation.
-    foreach ($this->langcodes as $index => $langcode) {
+    foreach ($this->langcodes as $langcode) {
       $user = $this->drupalCreateUser();
       $values[$langcode] = [
         'uid' => $user->id(),
diff --git a/core/modules/editor/tests/src/FunctionalJavascript/EditorAdminTest.php b/core/modules/editor/tests/src/FunctionalJavascript/EditorAdminTest.php
index c48eef11ae87..95879450d56d 100644
--- a/core/modules/editor/tests/src/FunctionalJavascript/EditorAdminTest.php
+++ b/core/modules/editor/tests/src/FunctionalJavascript/EditorAdminTest.php
@@ -80,7 +80,6 @@ public function testEditorSelection(): void {
    */
   public function testEditorCreation(): void {
     $page = $this->getSession()->getPage();
-    $assert_session = $this->assertSession();
 
     $this->drupalGet('/admin/config/content/formats/add');
     $page->fillField('name', $this->randomString());
diff --git a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
index 108cedefed92..fa1e0ca27d86 100644
--- a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
+++ b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
@@ -320,7 +320,7 @@ public function testPrivateFileComment(): void {
     $text_file = $this->getTestFile('text');
     $edit = [
       'files[field_' . $name . '_' . 0 . ']' => \Drupal::service('file_system')->realpath($text_file->getFileUri()),
-      'comment_body[0][value]' => $comment_body = $this->randomMachineName(),
+      'comment_body[0][value]' => $this->randomMachineName(),
     ];
     $this->drupalGet('node/' . $node->id());
     $this->submitForm($edit, 'Save');
@@ -367,7 +367,6 @@ public function testWidgetValidation(): void {
     $this->createFileField($field_name, 'node', $type_name);
     $this->updateFileField($field_name, $type_name, ['file_extensions' => 'txt']);
 
-    $type = 'nojs';
     // Create node and prepare files for upload.
     $node = $this->drupalCreateNode(['type' => 'article']);
     $nid = $node->id();
diff --git a/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php b/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php
index e2e1481617cc..781c35959173 100644
--- a/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php
+++ b/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php
@@ -112,7 +112,7 @@ public function testRoutes(): void {
       'related' => "/jsonapi/entity_test_no_label/entity_test_no_label/{$this->internalEntity->uuid()}/field_internal",
     ];
     $this->drupalLogin($this->testUser);
-    foreach ($paths as $type => $path) {
+    foreach ($paths as $path) {
       $this->drupalGet($path, ['Accept' => 'application/vnd.api+json']);
       $this->assertSame(404, $this->getSession()->getStatusCode());
     }
diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
index 9dd535bedd5e..1395209a064b 100644
--- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
+++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
@@ -2563,7 +2563,7 @@ protected static function recursiveKsort(array &$array) {
     ksort($array);
 
     // Then check for child arrays.
-    foreach ($array as $key => &$value) {
+    foreach ($array as &$value) {
       if (is_array($value)) {
         static::recursiveKsort($value);
       }
@@ -2758,7 +2758,7 @@ protected function doTestIncluded(Url $url, array $request_options) {
       }
     }
 
-    foreach ($field_sets as $type => $included_paths) {
+    foreach ($field_sets as $included_paths) {
       $this->grantIncludedPermissions($included_paths);
       $query = ['include' => implode(',', $included_paths)];
       $url->setOption('query', $query);
diff --git a/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php b/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
index 1691c5d40138..32ec3a2c6e51 100644
--- a/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
@@ -429,11 +429,9 @@ public function testLanguageBodyClass(): void {
    * @see self::testLanguageLinkActiveClass()
    */
   protected function doTestLanguageLinkActiveClassAuthenticated(): void {
-    $function_name = '#type link';
     $path = 'language_test/type-link-active-class';
 
     // Test links generated by the link generator on an English page.
-    $current_language = 'English';
     $this->drupalGet($path);
 
     // Language code 'none' link should be active.
@@ -454,7 +452,6 @@ protected function doTestLanguageLinkActiveClassAuthenticated(): void {
     $this->assertSame('en', $settings['path']['currentLanguage'], 'drupalSettings.path.currentLanguage is set correctly to allow drupal.active-link to mark the correct links as active.');
 
     // Test links generated by the link generator on a French page.
-    $current_language = 'French';
     $this->drupalGet('fr/language_test/type-link-active-class');
 
     // Language code 'none' link should be active.
@@ -481,12 +478,9 @@ protected function doTestLanguageLinkActiveClassAuthenticated(): void {
    * @see self::testLanguageLinkActiveClass()
    */
   protected function doTestLanguageLinkActiveClassAnonymous(): void {
-    $function_name = '#type link';
-
     $this->drupalLogout();
 
     // Test links generated by the link generator on an English page.
-    $current_language = 'English';
     $this->drupalGet('language_test/type-link-active-class');
 
     // Language code 'none' link should be active.
@@ -499,7 +493,6 @@ protected function doTestLanguageLinkActiveClassAnonymous(): void {
     $this->assertSession()->elementExists('xpath', "//a[@id = 'fr_link' and not(contains(@class, 'is-active'))]");
 
     // Test links generated by the link generator on a French page.
-    $current_language = 'French';
     $this->drupalGet('fr/language_test/type-link-active-class');
 
     // Language code 'none' link should be active.
diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/AjaxBlockTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/AjaxBlockTest.php
index 220a61ad1d2e..bf33b3d7c789 100644
--- a/core/modules/layout_builder/tests/src/FunctionalJavascript/AjaxBlockTest.php
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/AjaxBlockTest.php
@@ -60,7 +60,6 @@ protected function setUp(): void {
    */
   public function testAddAjaxBlock(): void {
     $assert_session = $this->assertSession();
-    $page = $this->getSession()->getPage();
 
     // Start by creating a node.
     $this->createNode([
@@ -95,7 +94,7 @@ public function testAddAjaxBlock(): void {
     /** @var \Behat\Mink\Element\NodeElement[] $radios */
     $radios = $this->assertSession()->fieldExists($name);
     // Click them both a couple of times.
-    foreach ([1, 2] as $rounds) {
+    for ($i = 1; $i < 3; ++$i) {
       foreach ($radios as $radio) {
         $radio->click();
         $assert_session->assertWaitOnAjaxRequest();
diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php
index 22ef2b12705e..8a13b0e070cf 100644
--- a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php
+++ b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php
@@ -106,7 +106,6 @@ public function testWidgetOverflow(?string $selected_operation): void {
     }
 
     $assert_session = $this->assertSession();
-    $page = $this->getSession()->getPage();
     $this->drupalGet('node/add/basic_page');
     // Upload 5 files into a media field that only allows 2.
     $this->openMediaLibraryForField('field_twin_media');
diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
index 40a1f70c987e..7e0b3af57f0b 100644
--- a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
+++ b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
@@ -301,7 +301,7 @@ public function testWidgetUpload(): void {
     // Create a list of new files to upload.
     $filenames = [];
     $remote_paths = [];
-    foreach (range(1, 4) as $i) {
+    for ($i = 1; $i < 5; $i++) {
       $path = $file_system->copy($png_image->uri, 'public://');
       $filenames[] = $file_system->basename($path);
       $remote_paths[] = $driver->uploadFileAndGetRemoteFilePath($file_system->realpath($path));
@@ -680,7 +680,7 @@ public function testWidgetUploadAdvancedUi(): void {
     // Create a list of new files to upload.
     $filenames = [];
     $remote_paths = [];
-    foreach (range(1, 4) as $i) {
+    for ($i = 1; $i < 5; $i++) {
       $path = $file_system->copy($png_image->uri, 'public://');
       $filenames[] = $file_system->basename($path);
       $remote_paths[] = $driver->uploadFileAndGetRemoteFilePath($file_system->realpath($path));
diff --git a/core/modules/node/tests/src/Functional/PagePreviewTest.php b/core/modules/node/tests/src/Functional/PagePreviewTest.php
index 5caa943e084b..c30ebc17bc1d 100644
--- a/core/modules/node/tests/src/Functional/PagePreviewTest.php
+++ b/core/modules/node/tests/src/Functional/PagePreviewTest.php
@@ -229,7 +229,7 @@ public function testPagePreview(): void {
     // Get the UUID.
     $url = parse_url($this->getUrl());
     $paths = explode('/', $url['path']);
-    $view_mode = array_pop($paths);
+    array_pop($paths);
     $uuid = array_pop($paths);
 
     // Switch view mode. We'll remove the body from the teaser view mode.
diff --git a/core/modules/package_manager/tests/src/Functional/FailureMarkerRequirementTest.php b/core/modules/package_manager/tests/src/Functional/FailureMarkerRequirementTest.php
index c0a84c830651..aac2498a9375 100644
--- a/core/modules/package_manager/tests/src/Functional/FailureMarkerRequirementTest.php
+++ b/core/modules/package_manager/tests/src/Functional/FailureMarkerRequirementTest.php
@@ -51,6 +51,7 @@ public function __construct() {}
       /**
        * {@inheritdoc}
        */
+      // phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable
       protected string $type = 'test';
     };
     $failure_marker->write($stage, $message);
diff --git a/core/modules/rest/tests/src/Functional/ResourceTest.php b/core/modules/rest/tests/src/Functional/ResourceTest.php
index fc39ea210b49..dc742ed835bc 100644
--- a/core/modules/rest/tests/src/Functional/ResourceTest.php
+++ b/core/modules/rest/tests/src/Functional/ResourceTest.php
@@ -155,8 +155,8 @@ public function testUriPaths(): void {
     /** @var \Drupal\rest\Plugin\Type\ResourcePluginManager $manager */
     $manager = \Drupal::service('plugin.manager.rest');
 
-    foreach ($manager->getDefinitions() as $resource => $definition) {
-      foreach ($definition['uri_paths'] as $key => $uri_path) {
+    foreach ($manager->getDefinitions() as $definition) {
+      foreach ($definition['uri_paths'] as $uri_path) {
         $this->assertStringNotContainsString('//', $uri_path, 'The resource URI path does not have duplicate slashes.');
       }
     }
diff --git a/core/modules/rest/tests/src/Functional/ResourceTestBase.php b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
index adc598f905ff..73aeef3fe7b7 100644
--- a/core/modules/rest/tests/src/Functional/ResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
@@ -441,7 +441,7 @@ protected static function recursiveKSort(array &$array) {
     ksort($array);
 
     // Then check for child arrays.
-    foreach ($array as $key => &$value) {
+    foreach ($array as &$value) {
       if (is_array($value)) {
         static::recursiveKSort($value);
       }
diff --git a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
index ccf958bf18c0..b30bc34ae97e 100644
--- a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
+++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
@@ -111,7 +111,7 @@ public function testRestViewsAuthentication(): void {
     // Ensure that any changes to variables in the other thread are picked up.
     $this->refreshVariables();
 
-    $this->assertSession()->statusCodeEquals(200);
+    $this->assertEquals(200, $response->getStatusCode());
   }
 
   /**
diff --git a/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php b/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php
index 4e5695141b6a..4a85815ac881 100644
--- a/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php
+++ b/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php
@@ -51,7 +51,6 @@ public function testOrder(): void {
     $asset_resolver = \Drupal::service('asset.resolver');
     $css_collection_renderer = \Drupal::service('asset.css.collection_renderer');
     $js_collection_renderer = \Drupal::service('asset.js.collection_renderer');
-    $renderer = \Drupal::service('renderer');
     $build['#attached']['library'][] = 'ajax_test/order-css-command';
     $assets = AttachedAssets::createFromRenderArray($build);
     $css_render_array = $css_collection_renderer->render($asset_resolver->getCssAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage()));
diff --git a/core/modules/system/tests/src/Functional/DrupalKernel/ContentNegotiationTest.php b/core/modules/system/tests/src/Functional/DrupalKernel/ContentNegotiationTest.php
index 2e5e2e947bbd..274c6044c380 100644
--- a/core/modules/system/tests/src/Functional/DrupalKernel/ContentNegotiationTest.php
+++ b/core/modules/system/tests/src/Functional/DrupalKernel/ContentNegotiationTest.php
@@ -44,7 +44,7 @@ public function testBogusAcceptHeader(): void {
       'Android #1 (2012)' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
       'Android #2 (2012)' => 'text/xml,text/html,application/xhtml+xml,image/png,text/plain,*/*;q=0.8',
     ];
-    foreach ($tests as $case => $header) {
+    foreach ($tests as $header) {
       $this->drupalGet('', [], ['Accept' => $header]);
       $this->assertSession()->pageTextNotContains('Unsupported Media Type');
       $this->assertSession()->pageTextContains('Log in');
diff --git a/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php b/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php
index 9cda40532a60..ccf0d3c42874 100644
--- a/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php
+++ b/core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php
@@ -37,10 +37,9 @@ public function testMultipleTrue(): void {
     // Test for the presence of the Select all rows tableheader.
     $this->assertSession()->elementExists('xpath', '//th[@class="select-all"]');
 
-    $rows = ['row1', 'row2', 'row3'];
-    foreach ($rows as $row) {
-      $this->assertSession()->elementExists('xpath', '//input[@type="checkbox"]');
-    }
+    $this->assertSession()->elementExists('xpath', '//input[@type="checkbox" and @value="row1"]');
+    $this->assertSession()->elementExists('xpath', '//input[@type="checkbox" and @value="row2"]');
+    $this->assertSession()->elementExists('xpath', '//input[@type="checkbox" and @value="row3"]');
   }
 
   /**
@@ -54,10 +53,9 @@ public function testMultipleFalse(): void {
     // Test for the absence of the Select all rows tableheader.
     $this->assertSession()->elementNotExists('xpath', '//th[@class="select-all"]');
 
-    $rows = ['row1', 'row2', 'row3'];
-    foreach ($rows as $row) {
-      $this->assertSession()->elementExists('xpath', '//input[@type="radio"]');
-    }
+    $this->assertSession()->elementExists('xpath', '//input[@type="radio" and @value="row1"]');
+    $this->assertSession()->elementExists('xpath', '//input[@type="radio" and @value="row2"]');
+    $this->assertSession()->elementExists('xpath', '//input[@type="radio" and @value="row3"]');
   }
 
   /**
diff --git a/core/modules/system/tests/src/Functional/Routing/RouterTest.php b/core/modules/system/tests/src/Functional/Routing/RouterTest.php
index a9f281f07d2f..46f4bc7f8618 100644
--- a/core/modules/system/tests/src/Functional/Routing/RouterTest.php
+++ b/core/modules/system/tests/src/Functional/Routing/RouterTest.php
@@ -53,7 +53,6 @@ public function testFinishResponseSubscriber(): void {
     $this->drupalGet('router_test/test2');
     $this->assertSession()->pageTextContains('test2');
     // Check expected headers from FinishResponseSubscriber.
-    $headers = $session->getResponseHeaders();
     $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Contexts', implode(' ', $expected_cache_contexts));
     $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'config:user.role.anonymous http_response rendered');
     $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Max-Age', '-1 (Permanent)');
diff --git a/core/modules/system/tests/src/Functional/System/DefaultMobileMetaTagsTest.php b/core/modules/system/tests/src/Functional/System/DefaultMobileMetaTagsTest.php
index e599884c2d20..28a9328afc23 100644
--- a/core/modules/system/tests/src/Functional/System/DefaultMobileMetaTagsTest.php
+++ b/core/modules/system/tests/src/Functional/System/DefaultMobileMetaTagsTest.php
@@ -40,7 +40,7 @@ protected function setUp(): void {
    */
   public function testDefaultMetaTagsExist(): void {
     $this->drupalGet('');
-    foreach ($this->defaultMetaTags as $name => $metatag) {
+    foreach ($this->defaultMetaTags as $metatag) {
       $this->assertSession()->responseContains($metatag);
     }
   }
@@ -51,7 +51,7 @@ public function testDefaultMetaTagsExist(): void {
   public function testRemovingDefaultMetaTags(): void {
     \Drupal::service('module_installer')->install(['system_module_test']);
     $this->drupalGet('');
-    foreach ($this->defaultMetaTags as $name => $metatag) {
+    foreach ($this->defaultMetaTags as $metatag) {
       $this->assertSession()->responseNotContains($metatag);
     }
   }
diff --git a/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php b/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php
index 010f1ccb5210..2e8c9176375f 100644
--- a/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php
+++ b/core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php
@@ -297,7 +297,7 @@ protected function assertUninstallableTheme(array $expected_requires_list_items,
     $requires_list_items = $theme_container->findAll('css', '.theme-info__requires li');
     $this->assertSameSize($expected_requires_list_items, $requires_list_items);
 
-    foreach ($requires_list_items as $key => $item) {
+    foreach ($requires_list_items as $item) {
       $this->assertContains($item->getText(), $expected_requires_list_items);
     }
 
diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
index c232652ae3b1..4947ea689942 100644
--- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
@@ -46,9 +46,9 @@ protected function setUp(): void {
   public function testTermIndentation(): void {
     $assert = $this->assertSession();
     // Create three taxonomy terms.
-    $term1 = $this->createTerm($this->vocabulary);
+    $this->createTerm($this->vocabulary);
     $term2 = $this->createTerm($this->vocabulary);
-    $term3 = $this->createTerm($this->vocabulary);
+    $this->createTerm($this->vocabulary);
 
     // Get the taxonomy storage.
     $taxonomy_storage = $this->container->get('entity_type.manager')->getStorage('taxonomy_term');
diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php
index 2078d9e2d99e..9ea1ef323a38 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php
@@ -138,8 +138,6 @@ public function testTaxonomyTermChildTerms(): void {
     $term1 = $this->createTerm($this->vocabulary);
     $terms_array = [];
 
-    $taxonomy_storage = $this->container->get('entity_type.manager')->getStorage('taxonomy_term');
-
     // Create 40 terms. Terms 1-12 get parent of $term1. All others are
     // individual terms.
     for ($x = 1; $x <= 40; $x++) {
@@ -152,8 +150,6 @@ public function testTaxonomyTermChildTerms(): void {
         $edit['parent'] = $term1->id();
       }
       $term = $this->createTerm($this->vocabulary, $edit);
-      $children = $taxonomy_storage->loadChildren($term1->id());
-      $parents = $taxonomy_storage->loadParents($term->id());
       $terms_array[$x] = Term::load($term->id());
     }
 
diff --git a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldAllTermsTest.php b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldAllTermsTest.php
index 52e07caf7b31..0126d73a4d2c 100644
--- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldAllTermsTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldAllTermsTest.php
@@ -55,7 +55,6 @@ public function testViewsHandlerAllTermsField(): void {
    * Tests token replacement in the "all terms" field handler.
    */
   public function testViewsHandlerAllTermsWithTokens(): void {
-    $view = Views::getView('taxonomy_all_terms_test');
     $this->drupalGet('taxonomy_all_terms_token_test');
 
     // Term itself: {{ term_node_tid }}
diff --git a/core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php b/core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php
index 5bdfc88c3904..7747682a42ec 100644
--- a/core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php
@@ -144,7 +144,7 @@ public function testTaxonomyAdminChangingWeights(): void {
   public function testTaxonomyAdminNoVocabularies(): void {
     // Delete all vocabularies.
     $vocabularies = Vocabulary::loadMultiple();
-    foreach ($vocabularies as $key => $vocabulary) {
+    foreach ($vocabularies as $vocabulary) {
       $vocabulary->delete();
     }
     // Confirm that no vocabularies are found in the database.
diff --git a/core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php b/core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php
index 52b89b001359..c55362495b2f 100644
--- a/core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php
+++ b/core/modules/user/tests/src/Functional/Views/UserFieldsAccessChangeTest.php
@@ -64,11 +64,6 @@ public function testUserNameLink(): void {
     $test_user = $this->drupalCreateUser();
     $xpath = "//td/a[.='" . $test_user->getAccountName() . "']/@href[.='" . $test_user->toUrl()->toString() . "']";
 
-    $attributes = [
-      'title' => 'View user profile.',
-    ];
-    $link = $test_user->toLink(NULL, 'canonical', ['attributes' => $attributes])->toString();
-
     // No access, so no link.
     $this->drupalGet('test_user_fields_access');
     $this->assertSession()->pageTextContains($test_user->getAccountName());
diff --git a/core/modules/views/tests/src/Functional/BulkFormTest.php b/core/modules/views/tests/src/Functional/BulkFormTest.php
index c5aeba4acb32..16de73e12534 100644
--- a/core/modules/views/tests/src/Functional/BulkFormTest.php
+++ b/core/modules/views/tests/src/Functional/BulkFormTest.php
@@ -232,7 +232,7 @@ public function testBulkForm(): void {
     // by another user before the loaded bulk form was submitted.
     $this->drupalGet('test_bulk_form');
     // Call the node delete action.
-    foreach ($nodes as $key => $node) {
+    foreach ($nodes as $node) {
       $node->delete();
     }
     $edit = [
diff --git a/core/modules/views/tests/src/Functional/Plugin/PagerTest.php b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php
index c43d3574ac5e..bfa91aade6bf 100644
--- a/core/modules/views/tests/src/Functional/Plugin/PagerTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php
@@ -105,7 +105,7 @@ public function testStorePagerSettings(): void {
     $this->assertSame('number', $offset->getAttribute('type'));
     $this->assertEquals(0, $offset->getAttribute('min'));
 
-    $pagerHeading = $this->assertSession()->fieldExists("pager_options[pagination_heading_level]");
+    $this->assertSession()->fieldExists("pager_options[pagination_heading_level]");
     $this->assertSession()->fieldValueEquals("pager_options[pagination_heading_level]", 'h4');
 
     $id = $this->assertSession()->fieldExists("pager_options[id]");
@@ -539,7 +539,7 @@ public function testPagerConfigTranslation(): void {
       'Next ›' => 'Volgende ›',
       'Last »' => 'Laatste »',
     ];
-    foreach ($labels as $label => $translation) {
+    foreach ($labels as $translation) {
       // Check if we can find the translation.
       $this->assertSession()->pageTextContains($translation);
     }
diff --git a/core/modules/views_ui/tests/src/Functional/DisplayTest.php b/core/modules/views_ui/tests/src/Functional/DisplayTest.php
index b9cf5d43dd96..eebd1861d59b 100644
--- a/core/modules/views_ui/tests/src/Functional/DisplayTest.php
+++ b/core/modules/views_ui/tests/src/Functional/DisplayTest.php
@@ -37,7 +37,7 @@ class DisplayTest extends UITestBase {
    * Tests adding a display.
    */
   public function testAddDisplay(): void {
-    $view = $this->randomView();
+    $this->randomView();
     $this->assertSession()->elementNotExists('xpath', '//li[@data-drupal-selector="edit-displays-top-tabs-block-1"]');
     $this->assertSession()->elementNotExists('xpath', '//li[@data-drupal-selector="edit-displays-top-tabs-block-2"]');
     $this->assertSession()->pageTextMatchesCount(0, '/Block name:/');
diff --git a/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php b/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php
index 74cadc64d628..2cfc383f5c77 100644
--- a/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php
+++ b/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php
@@ -59,7 +59,7 @@ public function testFilterUi(): void {
       return strnatcasecmp($a->getTitle(), $b->getTitle());
     });
     $i = 0;
-    foreach ($this->targetEntities as $id => $entity) {
+    foreach ($this->targetEntities as $entity) {
       $message = (string) new FormattableMarkup('Expected target entity label found for option :option', [':option' => $i]);
       $this->assertEquals($options[$i]['label'], $entity->label(), $message);
       $i++;
diff --git a/core/modules/views_ui/tests/src/Functional/HandlerTest.php b/core/modules/views_ui/tests/src/Functional/HandlerTest.php
index affa94522725..0c1db3845476 100644
--- a/core/modules/views_ui/tests/src/Functional/HandlerTest.php
+++ b/core/modules/views_ui/tests/src/Functional/HandlerTest.php
@@ -232,7 +232,7 @@ public function testBrokenHandlers(): void {
 
       // Test that the handler edit link is present.
       $this->assertSession()->elementsCount('xpath', "//a[contains(@href, '{$href}')]", 1);
-      $result = $this->assertSession()->elementTextEquals('xpath', "//a[contains(@href, '{$href}')]", $text);
+      $this->assertSession()->elementTextEquals('xpath', "//a[contains(@href, '{$href}')]", $text);
 
       $this->drupalGet($href);
       $this->assertSession()->elementTextContains('xpath', '//h1', $text);
diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist
index 1144bf1f37d0..4812975b327e 100644
--- a/core/phpcs.xml.dist
+++ b/core/phpcs.xml.dist
@@ -154,8 +154,7 @@
 
   <!-- Drupal Practice sniffs -->
   <rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis">
-    <exclude-pattern>*/Functional/*</exclude-pattern>
-    <exclude-pattern>*/FunctionalJavascript/*</exclude-pattern>
+    <exclude-pattern>*/core/tests/*</exclude-pattern>
     <exclude-pattern>*/core/profiles/*/tests/*</exclude-pattern>
     <!-- Do not run this sniff on API files or transliteration data. -->
     <exclude-pattern>*.api.php</exclude-pattern>
diff --git a/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php b/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php
index 0a100c52d7b4..897b59bb0027 100644
--- a/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php
+++ b/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php
@@ -209,7 +209,7 @@ protected function testLogin(): void {
     // form so that we repeat the same steps when recording performance data. Do
     // this twice so that any caches which take two requests to warm are also
     // covered.
-    foreach (range(0, 1) as $index) {
+    for ($i = 0; $i < 2; $i++) {
       $this->drupalGet('node');
       $this->drupalGet('user/login');
       $this->submitLoginForm($this->user);
@@ -262,7 +262,7 @@ protected function testLoginBlock(): void {
     // we repeat the same steps when recording performance data. Do this twice
     // so that any caches which take two requests to warm are also covered.
 
-    foreach (range(0, 1) as $index) {
+    for ($i = 0; $i < 2; $i++) {
       $this->drupalGet('node');
       $this->assertSession()->responseContains('Password');
       $this->submitLoginForm($this->user);
diff --git a/core/profiles/standard/tests/src/Traits/StandardTestTrait.php b/core/profiles/standard/tests/src/Traits/StandardTestTrait.php
index 3f67accf8a21..6b1ae846acf1 100644
--- a/core/profiles/standard/tests/src/Traits/StandardTestTrait.php
+++ b/core/profiles/standard/tests/src/Traits/StandardTestTrait.php
@@ -254,7 +254,6 @@ function (ConstraintViolation $v) {
     $role->save();
     $this->adminUser->addRole($role->id())->save();
     $assert_session = $this->assertSession();
-    $page = $this->getSession()->getPage();
     /** @var \Drupal\media\Entity\MediaType $media_type */
     foreach (MediaType::loadMultiple() as $media_type) {
       $media_type_machine_name = $media_type->id();
-- 
GitLab