From c6626e6e0ab998271bc39a22986c10790530e360 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Tue, 18 Feb 2025 12:36:43 -0500 Subject: [PATCH 1/6] Add BC layer in phpstan --- phpstan.neon | 15 +++------------ phpstan/baseline-no-getExtras.neon | 11 +++++++++++ phpstan/drupal-core-bc-layer.neon.php | 12 ++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 phpstan/baseline-no-getExtras.neon create mode 100644 phpstan/drupal-core-bc-layer.neon.php diff --git a/phpstan.neon b/phpstan.neon index 68afe1135..bf0fae576 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,12 @@ +includes: + - phpstan/drupal-core-bc-layer.neon.php parameters: level: 8 universalObjectCratesClasses: - Drupal\Core\Extension\Extension reportUnmatchedIgnoredErrors: true excludePaths: + - phpstan/drupal-core-bc-layer.neon.php # The scripts directory does not contain runtime code. - scripts # The node_modules contains some PHP to ignore. @@ -44,18 +47,6 @@ parameters: - tests/src/Functional - tests/src/FunctionalJavascript reportUnmatched: false - # @todo Remove the next two ignores when Drupal 11.1.3 is the minimum supported version of core. - - - message: "#^Call to an undefined method Drupal\\\\Core\\\\Recipe\\\\Recipe\\:\\:getExtra\\(\\)\\.$#" - count: 1 - path: src/Activator/RecipeActivator.php - reportUnmatched: false - - - message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to (true|false)\\.$#" - paths: - - src/Activator/RecipeActivator.php - - tests/src/Kernel/RecipeActivatorTest.php - reportUnmatched: false ### Package Manager # @todo Remove after resolving https://www.drupal.org/i/3501836. diff --git a/phpstan/baseline-no-getExtras.neon b/phpstan/baseline-no-getExtras.neon new file mode 100644 index 000000000..608aa648e --- /dev/null +++ b/phpstan/baseline-no-getExtras.neon @@ -0,0 +1,11 @@ +parameters: + ignoreErrors: + - + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to (true|false)\\.$#" + paths: + - ../src/Activator/RecipeActivator.php + - ../tests/src/Kernel/RecipeActivatorTest.php + - + message: "#^Call to an undefined method Drupal\\\\Core\\\\Recipe\\\\Recipe\\:\\:getExtra\\(\\)\\.$#" + paths: + - ../src/Activator/RecipeActivator.php diff --git a/phpstan/drupal-core-bc-layer.neon.php b/phpstan/drupal-core-bc-layer.neon.php new file mode 100644 index 000000000..f5383df4b --- /dev/null +++ b/phpstan/drupal-core-bc-layer.neon.php @@ -0,0 +1,12 @@ +<?php declare(strict_types = 1); + +use Drupal\Core\Recipe\Recipe; + +$includes = []; +if (!method_exists(Recipe::class, 'getExtra')) { + $includes[] = __DIR__ . '/baseline-no-getExtras.neon'; +} + +$config = []; +$config['includes'] = $includes; +return $config; -- GitLab From 02476a696cff63258a6796f4ab10d98d157bed14 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Tue, 18 Feb 2025 12:47:09 -0500 Subject: [PATCH 2/6] Fix PHPCS --- phpstan/drupal-core-bc-layer.neon.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpstan/drupal-core-bc-layer.neon.php b/phpstan/drupal-core-bc-layer.neon.php index f5383df4b..2e6070f02 100644 --- a/phpstan/drupal-core-bc-layer.neon.php +++ b/phpstan/drupal-core-bc-layer.neon.php @@ -1,4 +1,11 @@ -<?php declare(strict_types = 1); +<?php + +/** + * @file + * Allows for specific PHPStan ignores for different versions of Drupal core. + */ + +declare(strict_types = 1); use Drupal\Core\Recipe\Recipe; -- GitLab From 3e9176d160ed9cd8e53a1d486aefde1d28723e36 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Tue, 18 Feb 2025 12:49:54 -0500 Subject: [PATCH 3/6] Move out of directory --- ...-no-getExtras.neon => phpstan-baseline-no-getExtras.neon | 6 +++--- ...-layer.neon.php => phpstan-drupal-core-bc-layer.neon.php | 2 +- phpstan.neon | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename phpstan/baseline-no-getExtras.neon => phpstan-baseline-no-getExtras.neon (69%) rename phpstan/drupal-core-bc-layer.neon.php => phpstan-drupal-core-bc-layer.neon.php (81%) diff --git a/phpstan/baseline-no-getExtras.neon b/phpstan-baseline-no-getExtras.neon similarity index 69% rename from phpstan/baseline-no-getExtras.neon rename to phpstan-baseline-no-getExtras.neon index 608aa648e..c2965b58f 100644 --- a/phpstan/baseline-no-getExtras.neon +++ b/phpstan-baseline-no-getExtras.neon @@ -3,9 +3,9 @@ parameters: - message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to (true|false)\\.$#" paths: - - ../src/Activator/RecipeActivator.php - - ../tests/src/Kernel/RecipeActivatorTest.php + - src/Activator/RecipeActivator.php + - tests/src/Kernel/RecipeActivatorTest.php - message: "#^Call to an undefined method Drupal\\\\Core\\\\Recipe\\\\Recipe\\:\\:getExtra\\(\\)\\.$#" paths: - - ../src/Activator/RecipeActivator.php + - src/Activator/RecipeActivator.php diff --git a/phpstan/drupal-core-bc-layer.neon.php b/phpstan-drupal-core-bc-layer.neon.php similarity index 81% rename from phpstan/drupal-core-bc-layer.neon.php rename to phpstan-drupal-core-bc-layer.neon.php index 2e6070f02..48115c817 100644 --- a/phpstan/drupal-core-bc-layer.neon.php +++ b/phpstan-drupal-core-bc-layer.neon.php @@ -11,7 +11,7 @@ use Drupal\Core\Recipe\Recipe; $includes = []; if (!method_exists(Recipe::class, 'getExtra')) { - $includes[] = __DIR__ . '/baseline-no-getExtras.neon'; + $includes[] = __DIR__ . '/phpstan-baseline-no-getExtras.neon'; } $config = []; diff --git a/phpstan.neon b/phpstan.neon index bf0fae576..7310ed6f2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,12 +1,12 @@ includes: - - phpstan/drupal-core-bc-layer.neon.php + - phpstan-drupal-core-bc-layer.neon.php parameters: level: 8 universalObjectCratesClasses: - Drupal\Core\Extension\Extension reportUnmatchedIgnoredErrors: true excludePaths: - - phpstan/drupal-core-bc-layer.neon.php + - phpstan-drupal-core-bc-layer.neon.php # The scripts directory does not contain runtime code. - scripts # The node_modules contains some PHP to ignore. -- GitLab From 3c1f2cc70e1bb683022f260b6a1feb27283fb2d8 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Tue, 18 Feb 2025 13:06:03 -0500 Subject: [PATCH 4/6] Update for PHPStan 2 --- phpstan-baseline-getExtras.neon | 7 +++++++ phpstan-baseline-no-getExtras.neon | 2 +- phpstan-drupal-core-bc-layer.neon.php | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 phpstan-baseline-getExtras.neon diff --git a/phpstan-baseline-getExtras.neon b/phpstan-baseline-getExtras.neon new file mode 100644 index 000000000..8e58c7d23 --- /dev/null +++ b/phpstan-baseline-getExtras.neon @@ -0,0 +1,7 @@ +parameters: + ignoreErrors: + - + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to true\\.$#" + paths: + - src/Activator/RecipeActivator.php + - tests/src/Kernel/RecipeActivatorTest.php diff --git a/phpstan-baseline-no-getExtras.neon b/phpstan-baseline-no-getExtras.neon index c2965b58f..66d9f032d 100644 --- a/phpstan-baseline-no-getExtras.neon +++ b/phpstan-baseline-no-getExtras.neon @@ -1,7 +1,7 @@ parameters: ignoreErrors: - - message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to (true|false)\\.$#" + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to false\\.$#" paths: - src/Activator/RecipeActivator.php - tests/src/Kernel/RecipeActivatorTest.php diff --git a/phpstan-drupal-core-bc-layer.neon.php b/phpstan-drupal-core-bc-layer.neon.php index 48115c817..04ca5fa5f 100644 --- a/phpstan-drupal-core-bc-layer.neon.php +++ b/phpstan-drupal-core-bc-layer.neon.php @@ -10,7 +10,10 @@ declare(strict_types = 1); use Drupal\Core\Recipe\Recipe; $includes = []; -if (!method_exists(Recipe::class, 'getExtra')) { +if (method_exists(Recipe::class, 'getExtra')) { + $includes[] = __DIR__ . '/phpstan-baseline-getExtras.neon'; +} +else { $includes[] = __DIR__ . '/phpstan-baseline-no-getExtras.neon'; } -- GitLab From 012be9156a9254dc53472aedba7459dfe94051c6 Mon Sep 17 00:00:00 2001 From: Fran Garcia-Linares <14157-fjgarlin@users.noreply.drupalcode.org> Date: Wed, 19 Feb 2025 15:27:42 +0000 Subject: [PATCH 5/6] Remove dir. --- phpstan-drupal-core-bc-layer.neon.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan-drupal-core-bc-layer.neon.php b/phpstan-drupal-core-bc-layer.neon.php index 04ca5fa5f..29c3d3058 100644 --- a/phpstan-drupal-core-bc-layer.neon.php +++ b/phpstan-drupal-core-bc-layer.neon.php @@ -11,10 +11,10 @@ use Drupal\Core\Recipe\Recipe; $includes = []; if (method_exists(Recipe::class, 'getExtra')) { - $includes[] = __DIR__ . '/phpstan-baseline-getExtras.neon'; + $includes[] = 'phpstan-baseline-getExtras.neon'; } else { - $includes[] = __DIR__ . '/phpstan-baseline-no-getExtras.neon'; + $includes[] = 'phpstan-baseline-no-getExtras.neon'; } $config = []; -- GitLab From cb1204cfb077e0160e7ab3a236472dfe73567746 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Wed, 19 Feb 2025 11:44:37 -0500 Subject: [PATCH 6/6] Be explicit with identifiers and counts (where applicable) --- phpstan-baseline-getExtras.neon | 11 ++++++++--- phpstan-baseline-no-getExtras.neon | 16 +++++++++++----- phpstan.neon | 7 +++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/phpstan-baseline-getExtras.neon b/phpstan-baseline-getExtras.neon index 8e58c7d23..b04ea759e 100644 --- a/phpstan-baseline-getExtras.neon +++ b/phpstan-baseline-getExtras.neon @@ -2,6 +2,11 @@ parameters: ignoreErrors: - message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to true\\.$#" - paths: - - src/Activator/RecipeActivator.php - - tests/src/Kernel/RecipeActivatorTest.php + identifier: function.alreadyNarrowedType + count: 1 + path: src/Activator/RecipeActivator.php + - + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to true\\.$#" + identifier: function.alreadyNarrowedType + count: 1 + path: tests/src/Kernel/RecipeActivatorTest.php diff --git a/phpstan-baseline-no-getExtras.neon b/phpstan-baseline-no-getExtras.neon index 66d9f032d..c05360dad 100644 --- a/phpstan-baseline-no-getExtras.neon +++ b/phpstan-baseline-no-getExtras.neon @@ -2,10 +2,16 @@ parameters: ignoreErrors: - message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to false\\.$#" - paths: - - src/Activator/RecipeActivator.php - - tests/src/Kernel/RecipeActivatorTest.php + identifier: function.impossibleType + count: 1 + path: src/Activator/RecipeActivator.php + - + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to false\\.$#" + identifier: function.impossibleType + count: 1 + path: tests/src/Kernel/RecipeActivatorTest.php - message: "#^Call to an undefined method Drupal\\\\Core\\\\Recipe\\\\Recipe\\:\\:getExtra\\(\\)\\.$#" - paths: - - src/Activator/RecipeActivator.php + identifier: method.notFound + count: 1 + path: src/Activator/RecipeActivator.php diff --git a/phpstan.neon b/phpstan.neon index 7310ed6f2..448f08b42 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,24 +25,28 @@ parameters: # Caused by missing return type on \Drupal\FunctionalJavascriptTests\WebDriverTestBase::assertSession(). - message: "#^Call to an undefined method Drupal\\\\Tests\\\\WebAssert\\:\\:assert[a-zA-Z]+\\(\\)\\.$#" + identifier: method.notFound paths: - tests/src/FunctionalJavascript reportUnmatched: false # Caused by missing return type on \Drupal\FunctionalJavascriptTests\WebDriverTestBase::assertSession(). - message: "#^Call to an undefined method Drupal\\\\Tests\\\\WebAssert\\:\\:wait[a-zA-Z]+\\(\\)\\.$#" + identifier: method.notFound paths: - tests/src/FunctionalJavascript reportUnmatched: false # Caused by \Drupal\KernelTests\KernelTestBase::$container having the wrong type. - message: "#^Property Drupal\\\\KernelTests\\\\KernelTestBase\\:\\:\\$container \\(Drupal\\\\Core\\\\DependencyInjection\\\\ContainerBuilder\\) does not accept Drupal\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\.$#" + identifier: assign.propertyType paths: - tests/src/Kernel/DatabaseTablesTest.php reportUnmatched: false # Caused by \Drupal\Tests\user\Traits\UserCreationTrait::createUser() returning FALSE instead of throwing an exception. - message: "#^Parameter \\#1 \\$account of method Drupal\\\\Tests\\\\BrowserTestBase\\:\\:drupalLogin\\(\\) expects Drupal\\\\Core\\\\Session\\\\AccountInterface, Drupal\\\\user\\\\Entity\\\\User\\|false given\\.$#" + identifier: argument.type paths: - tests/src/Functional - tests/src/FunctionalJavascript @@ -53,6 +57,7 @@ parameters: # Caused by using self instead of static as a return type in \Drupal\fixture_manipulator\FixtureManipulator. - message: "#^Method Drupal\\\\fixture_manipulator\\\\FixtureManipulator\\:\\:commitChanges\\(\\) invoked with 0 parameters, 1 required\\.$#" + identifier: arguments.count paths: - tests/src/Kernel/InstallerTest.php - tests/src/Kernel/CoreNotUpdatedValidatorTest.php @@ -61,12 +66,14 @@ parameters: # Caused by missing return type on \Drupal\Tests\package_manager\Traits\FixtureManipulatorTrait::getStageFixtureManipulator(). - message: "#^Call to an undefined method object\\:\\:setCorePackageVersion\\(\\)\\.$#" + identifier: method.notFound paths: - tests/src/Kernel/CoreNotUpdatedValidatorTest.php reportUnmatched: false # Caused by missing @throws on \Drupal\package_manager\StageBase::apply(). - message: "#^Dead catch \\- Drupal\\\\package_manager\\\\Exception\\\\StageEventException is never thrown in the try block\\.$#" + identifier: catch.neverThrown paths: - tests/src/Kernel/CoreNotUpdatedValidatorTest.php reportUnmatched: false -- GitLab