From 59f14c20d04e05ebfca5f1a0c904bdfc6e2f310b Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 17 Oct 2022 11:41:00 +0100 Subject: [PATCH] Issue #3259109 by mondrake, longwave, andregp, daffie, mglaman, neclimdul, alexpott: Fix 'Cannot unset offset' PHPStan L0 errors (cherry picked from commit 0bab40ee30dbc69bb65fb58fc28d546eb2a522e8) --- .../tests/src/Unit/MigrationStateUnitTest.php | 1 - .../views/display/DisplayPluginBase.php | 1 - .../PhpStorage/FileStorageReadOnlyTest.php | 4 +-- .../Component/PhpStorage/FileStorageTest.php | 4 +-- .../PhpStorage/PhpStorageTestBase.php | 4 +-- .../ActiveLinkResponseFilterTest.php | 34 +++++++------------ .../Core/Render/RendererPlaceholdersTest.php | 2 +- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php b/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php index 3c770c78471..ea4b54356ea 100644 --- a/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php @@ -396,7 +396,6 @@ MENU_UI // Test menu migration with menu_ui uninstalled. $tests[3] = $tests[1]; unset($tests[3]['modules_to_enable']['menu_ui']); - unset($tests[3]['files']['menu_ui']); unset($tests[3]['migrations']['menu_ui']); $tests[3]['expected_7'] = [ MigrationState::NOT_FINISHED => [ diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 338c5fe72d7..1803a150a2e 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -439,7 +439,6 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte // If the display cannot use a pager, then we cannot default it. if (!$this->usesPager()) { unset($sections['pager']); - unset($sections['items_per_page']); } foreach ($this->extenders as $extender) { diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php index c5df7508d6f..907f8c5688d 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php @@ -57,11 +57,11 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase { // Find a global that doesn't exist. do { - $random = mt_rand(10000, 100000); + $random = 'test' . mt_rand(10000, 100000); } while (isset($GLOBALS[$random])); // Write out a PHP file and ensure it's successfully loaded. - $code = "save($name, $code); $this->assertTrue($success); $php_read = new FileReadOnlyStorage($this->readonlyStorage); diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php index 2ad99b4b226..de5fbb21c25 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php @@ -70,11 +70,11 @@ class FileStorageTest extends PhpStorageTestBase { // Find a global that doesn't exist. do { - $random = mt_rand(10000, 100000); + $random = 'test' . mt_rand(10000, 100000); } while (isset($GLOBALS[$random])); // Write out a PHP file and ensure it's successfully loaded. - $code = "assertTrue($php->save($name, $code), 'Saved php file'); $php->load($name); $this->assertTrue($GLOBALS[$random], 'File saved correctly with correct value'); diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php b/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php index cc0e79d0e02..72903fe809c 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php @@ -39,11 +39,11 @@ abstract class PhpStorageTestBase extends TestCase { // Find a global that doesn't exist. do { - $random = mt_rand(10000, 100000); + $random = 'test' . mt_rand(10000, 100000); } while (isset($GLOBALS[$random])); // Write out a PHP file and ensure it's successfully loaded. - $code = "save($name, $code); $this->assertTrue($success, 'Saved php file'); $php->load($name); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php index 6d3be86b9b1..1efba0e6e6f 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php @@ -160,13 +160,11 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { // Matching path, plus all matching variations. $attributes = [ 'data-drupal-link-system-path' => 'llama', - 'data-drupal-link-query' => Json::encode(['foo' => 'bar']), ]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'nl']]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; // Matching path, plus all non-matching variations. - $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en']]; - unset($attributes['data-drupal-link-query']); + $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => TRUE]]; // Special non-matching path, plus all variations. @@ -176,7 +174,6 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl']]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en']]; - unset($attributes['data-drupal-link-query']); $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => TRUE]]; @@ -191,13 +188,11 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { // Matching path, plus all matching variations. $attributes = [ 'data-drupal-link-system-path' => 'llama', - 'data-drupal-link-query' => Json::encode(['foo' => 'bar']), ]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'nl']]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; // Matching path, plus all non-matching variations. - $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en']]; - unset($attributes['data-drupal-link-query']); + $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => TRUE]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => ""]]; @@ -209,7 +204,6 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl']]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en']]; - unset($attributes['data-drupal-link-query']); $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => TRUE]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => ""]]; @@ -226,13 +220,11 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { // Matching path, plus all matching variations. $attributes = [ 'data-drupal-link-system-path' => 'my-front-page', - 'data-drupal-link-query' => Json::encode(['foo' => 'bar']), ]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'en']]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; // Matching path, plus all non-matching variations. - $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl']]; - unset($attributes['data-drupal-link-query']); + $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => TRUE]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => ""]]; @@ -240,13 +232,11 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { // Special matching path, plus all variations. $attributes = [ 'data-drupal-link-system-path' => '', - 'data-drupal-link-query' => Json::encode(['foo' => 'bar']), ]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes]; - $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'en']]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; // Special matching path, plus all non-matching variations. - $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl']]; - unset($attributes['data-drupal-link-query']); + $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'nl', 'data-drupal-link-query' => Json::encode(['foo' => 'bar'])]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['data-drupal-link-query' => TRUE]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => ""]]; diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php index f9006bb3db5..4c815df3d0a 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -477,7 +477,7 @@ class RendererPlaceholdersTest extends RendererTestBase { // - uncacheable $x = $base_element_b; $expected_placeholder_render_array = $x['#attached']['placeholders'][(string) $generate_placeholder_markup()]; - unset($x['#attached']['placeholders'][(string) $generate_placeholder_markup()]['#cache']); + $this->assertArrayNotHasKey('#cache', $expected_placeholder_render_array); $cases[] = [ $x, $args,