diff --git a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
index bd4995934e5c1f48b4912c1f55797ff13eb5233b..b9c0ddd349e8bb89678accea2e89afccb24bcf39 100644
--- a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
+++ b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
@@ -208,10 +208,9 @@ public function testUnauthorizedErrorMessage() {
    * @see \Drupal\basic_auth\Authentication\Provider\BasicAuth::challengeException()
    */
   public function testCacheabilityOf401Response() {
-    $session = $this->getSession();
     $url = Url::fromRoute('router_test.11');
 
-    $assert_response_cacheability = function ($expected_page_cache_header_value, $expected_dynamic_page_cache_header_value) use ($session, $url) {
+    $assert_response_cacheability = function ($expected_page_cache_header_value, $expected_dynamic_page_cache_header_value) use ($url) {
       $this->drupalGet($url);
       $this->assertSession()->statusCodeEquals(401);
       $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', $expected_page_cache_header_value);
diff --git a/core/modules/config/tests/src/Functional/ConfigImportAllTest.php b/core/modules/config/tests/src/Functional/ConfigImportAllTest.php
index 72b4efd2b48f5ad4718edcbfaf7ae344a9d85679..c04c0eb9acaca1ee615f159d6c007eb2c60a3736 100644
--- a/core/modules/config/tests/src/Functional/ConfigImportAllTest.php
+++ b/core/modules/config/tests/src/Functional/ConfigImportAllTest.php
@@ -103,7 +103,7 @@ public function testInstallUninstall() {
     $validation_modules = array_keys($validation_reasons);
     $this->assertEqualsCanonicalizing($expected_modules, $validation_modules);
 
-    $modules_to_uninstall = array_filter($all_modules, function ($module) use ($validation_reasons) {
+    $modules_to_uninstall = array_filter($all_modules, function ($module) {
       // Filter required and not enabled modules.
       if (!empty($module->info['required']) || $module->status == FALSE) {
         return FALSE;
diff --git a/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php b/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php
index 6cb1b68c3842cfcea1c13b003b518ac8fdcbd05c..6b44315ac1c50b222d0fb8696ea4d3a52063c003 100644
--- a/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php
+++ b/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php
@@ -120,7 +120,7 @@ protected function assertAnnounceLeaveEditMode(): void {
     $web_assert = $this->assertSession();
     $page = $this->getSession()->getPage();
     // Wait till all the contextual links are hidden.
-    $page->waitFor(1, function () use ($page, $web_assert) {
+    $page->waitFor(1, function () use ($page) {
       return empty($page->find('css', '.contextual .trigger.visually-hidden'));
     });
     $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.');
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
index b7175788e978dade15b21b00ba5ec18ae506d014..46e58e7b0b3f6e0c4ecc8f1d050cbe763ce1d540 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -580,7 +580,7 @@ public function testGet() {
           ? $link_relation_type->getRegisteredName()
           : $link_relation_type->getExtensionUri();
       }, array_keys($this->entity->getEntityType()->getLinkTemplates()));
-      $parse_rel_from_link_header = function ($value) use ($link_relation_type_manager) {
+      $parse_rel_from_link_header = function ($value) {
         $matches = [];
         if (preg_match('/rel="([^"]+)"/', $value, $matches) === 1) {
           return $matches[1];
diff --git a/core/modules/system/tests/src/Kernel/Common/UrlTest.php b/core/modules/system/tests/src/Kernel/Common/UrlTest.php
index 76c5ffc45cd37b396795b972b5a425331f76bf5e..6ed9d626e3fd7a1aeedc8b4e336cc8e19c9df4f5 100644
--- a/core/modules/system/tests/src/Kernel/Common/UrlTest.php
+++ b/core/modules/system/tests/src/Kernel/Common/UrlTest.php
@@ -137,7 +137,7 @@ public function testLinkRenderArrayText() {
     $l = Link::fromTextAndUrl('foo', Url::fromUri('https://www.drupal.org'))->toString();
 
     // Test a renderable array passed to the link generator.
-    $renderer->executeInRenderContext(new RenderContext(), function () use ($renderer, $l) {
+    $renderer->executeInRenderContext(new RenderContext(), function () use ($l) {
       $renderable_text = ['#markup' => 'foo'];
       $l_renderable_text = \Drupal::service('link_generator')->generate($renderable_text, Url::fromUri('https://www.drupal.org'));
       $this->assertEquals($l, $l_renderable_text);
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index 99903f206da51c0cc0d8df150ed60cf48073bf21..d1129c65452991b917fff026a9144b8cd710aa44 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -785,11 +785,6 @@ parameters:
 			count: 1
 			path: modules/ban/src/Plugin/migrate/destination/BlockedIp.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$session\\.$#"
-			count: 1
-			path: modules/basic_auth/tests/src/Functional/BasicAuthTest.php
-
 		-
 			message: "#^\\#lazy_builder callback 'hello_or_yarhar' at key '0' is not callable\\.$#"
 			count: 1
@@ -990,11 +985,6 @@ parameters:
 			count: 2
 			path: modules/config/src/Form/ConfigSingleImportForm.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$validation_reasons\\.$#"
-			count: 1
-			path: modules/config/tests/src/Functional/ConfigImportAllTest.php
-
 		-
 			message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
 			count: 1
@@ -1075,11 +1065,6 @@ parameters:
 			count: 1
 			path: modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$web_assert\\.$#"
-			count: 1
-			path: modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php
-
 		-
 			message: "#^Variable \\$unrestricted_tab_count might not be defined\\.$#"
 			count: 1
@@ -1930,11 +1915,6 @@ parameters:
 			count: 1
 			path: modules/rest/src/Routing/ResourceRoutes.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$link_relation_type_manager\\.$#"
-			count: 1
-			path: modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
-
 		-
 			message: "#^Variable \\$created_entity might not be defined\\.$#"
 			count: 4
@@ -2155,11 +2135,6 @@ parameters:
 			count: 2
 			path: modules/system/tests/src/Functional/Theme/ThemeUiTest.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$renderer\\.$#"
-			count: 1
-			path: modules/system/tests/src/Kernel/Common/UrlTest.php
-
 		-
 			message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
 			count: 1
@@ -3150,11 +3125,6 @@ parameters:
 			count: 1
 			path: tests/Drupal/Tests/Core/Plugin/TestPluginManager.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$self\\.$#"
-			count: 1
-			path: tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
-
 		-
 			message: "#^\\#access_callback callback class '\\$this\\(Drupal\\\\Tests\\\\Core\\\\Render\\\\RendererCallbackTest\\)' at key '0' does not implement Drupal\\\\Core\\\\Security\\\\TrustedCallbackInterface\\.$#"
 			count: 1
@@ -3175,21 +3145,6 @@ parameters:
 			count: 1
 			path: tests/Drupal/Tests/Core/Render/RendererCallbackTest.php
 
-		-
-			message: "#^Anonymous function has an unused use \\$complex_child_template\\.$#"
-			count: 1
-			path: tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
-
-		-
-			message: "#^Anonymous function has an unused use \\$parent_markup\\.$#"
-			count: 1
-			path: tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
-
-		-
-			message: "#^Anonymous function has an unused use \\$renderer\\.$#"
-			count: 1
-			path: tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
-
 		-
 			message: "#^Variable \\$value in isset\\(\\) always exists and is not nullable\\.$#"
 			count: 1
diff --git a/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
index 3979f2cc07331cdb29caf76756f821908197d9c8..7bbdce9c43a1e07eb4fd786ba7a1d67b879c9e06 100644
--- a/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
@@ -55,7 +55,7 @@ public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata,
 
     $this->renderer->expects($this->exactly($invocations))
       ->method('render')
-      ->willReturnCallback(function ($build) use ($self) {
+      ->willReturnCallback(function ($build) {
         $this->assertArrayHasKey('#cache', $build);
       });
 
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
index 70b6a83dc3a0c46ff431675471c16905e8604bc9..ce26cf14d906076f12b32a2d526cd53ea733dab5 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
@@ -69,7 +69,7 @@ public function testRenderRecursionWithNestedRender() {
     $renderer = $this->renderer;
     $this->setUpRequest();
 
-    $callable = function ($markup) use ($renderer, $complex_child_template) {
+    $callable = function ($markup) {
       $this->assertStringStartsWith('<drupal-render-placeholder', $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
       return $markup;
     };
@@ -105,7 +105,7 @@ public function testRenderRecursionWithNestedRenderPlain() {
 
     $complex_child = $complex_child_template;
 
-    $callable = function ($elements) use ($renderer, $complex_child, $parent_markup) {
+    $callable = function ($elements) use ($renderer, $complex_child) {
       $elements['#markup'] = $renderer->renderPlain($complex_child);
       $this->assertEquals('<p>This is a rendered placeholder!</p>', $elements['#markup'], 'Rendered complex child output as expected, with the placeholder replaced.');
       return $elements;