diff --git a/phpstan-baseline-getExtras.neon b/phpstan-baseline-getExtras.neon new file mode 100644 index 0000000000000000000000000000000000000000..b04ea759e3a503c76f3512b2eccdc3531eb843b6 --- /dev/null +++ b/phpstan-baseline-getExtras.neon @@ -0,0 +1,12 @@ +parameters: + ignoreErrors: + - + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to true\\.$#" + 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 new file mode 100644 index 0000000000000000000000000000000000000000..c05360dadff0d2630522dcf75dcab83791cbed83 --- /dev/null +++ b/phpstan-baseline-no-getExtras.neon @@ -0,0 +1,17 @@ +parameters: + ignoreErrors: + - + message: "#^Call to function method_exists\\(\\) with 'Drupal\\\\\\\\Core\\\\\\\\Recipe\\\\\\\\Recipe' and 'getExtra' will always evaluate to false\\.$#" + 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\\(\\)\\.$#" + identifier: method.notFound + count: 1 + path: 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 0000000000000000000000000000000000000000..29c3d3058abf4a8046c9669ea4837a7622e1074c --- /dev/null +++ b/phpstan-drupal-core-bc-layer.neon.php @@ -0,0 +1,22 @@ +<?php + +/** + * @file + * Allows for specific PHPStan ignores for different versions of Drupal core. + */ + +declare(strict_types = 1); + +use Drupal\Core\Recipe\Recipe; + +$includes = []; +if (method_exists(Recipe::class, 'getExtra')) { + $includes[] = 'phpstan-baseline-getExtras.neon'; +} +else { + $includes[] = 'phpstan-baseline-no-getExtras.neon'; +} + +$config = []; +$config['includes'] = $includes; +return $config; diff --git a/phpstan.neon b/phpstan.neon index 68afe113502b7dcb2d44cb287a37bda0ec6e8c9c..448f08b420226dcd369aad291abbd26b56557a1c 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. @@ -22,46 +25,39 @@ 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 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. # 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 @@ -70,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