From 6ff703f92e1578480abb3997eadcd8d41a6ec17b Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Tue, 15 Apr 2025 14:26:12 -0400 Subject: [PATCH] Alternate approach --- composer.json | 2 +- phpstan-baseline-phpstan2-only.neon | 18 ++++++++++++++++++ phpstan-drupal-core-bc-layer.neon.php | 8 +++++++- src/Plugin/ProjectBrowserSource/SortHelper.php | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 phpstan-baseline-phpstan2-only.neon diff --git a/composer.json b/composer.json index ceb3887b6..17fc0492a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "colinodell/psr-testlogger": "^1.2", "drupal/automatic_updates": "^3.1.3", "drush/drush": "^12.5 || ^13", - "mglaman/phpstan-drupal": "<1.3.4, <2.0.2" + "mglaman/phpstan-drupal": "^1.3.7 || ^2.0.5" }, "conflict": { "drupal/automatic_updates": "<3.0", diff --git a/phpstan-baseline-phpstan2-only.neon b/phpstan-baseline-phpstan2-only.neon new file mode 100644 index 000000000..55cb7f8c0 --- /dev/null +++ b/phpstan-baseline-phpstan2-only.neon @@ -0,0 +1,18 @@ +parameters: + ignoreErrors: + - + message: '#^Call to static method Drupal\\Component\\Assertion\\Inspector\:\:assertAllObjects\(\) with array\<Drupal\\project_browser\\ProjectBrowser\\Project\> and ''Drupal\\\\project_browser\\\\ProjectBrowser\\\\Project'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Plugin/ProjectBrowserSource/SortHelper.php + - + message: '#^Call to static method Drupal\\Component\\Assertion\\Inspector\:\:assertAllStrings\(\) with array\<string\> will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Plugin/ProjectBrowserSource/SortHelper.php + + - + message: '#^Call to static method Drupal\\Component\\Assertion\\Inspector\:\:assertAllObjects\(\) with list\<Drupal\\project_browser\\ProjectBrowser\\Project\> and ''Drupal\\\\project_browser\\\\ProjectBrowser\\\\Project'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/ProjectBrowser/ProjectsResultsPage.php diff --git a/phpstan-drupal-core-bc-layer.neon.php b/phpstan-drupal-core-bc-layer.neon.php index 60d396acd..93b26d1b9 100644 --- a/phpstan-drupal-core-bc-layer.neon.php +++ b/phpstan-drupal-core-bc-layer.neon.php @@ -11,9 +11,11 @@ use Composer\InstalledVersions; use Composer\Semver\VersionParser; use Drupal\Core\Recipe\Recipe; +$is_phpstan2 = InstalledVersions::satisfies(new VersionParser(), 'phpstan/phpstan', '^2'); + $includes = []; if (method_exists(Recipe::class, 'getExtra')) { - if (InstalledVersions::satisfies(new VersionParser(), 'phpstan/phpstan', '^2')) { + if ($is_phpstan2) { $includes[] = 'phpstan-baseline-getExtras.neon'; } } @@ -21,6 +23,10 @@ else { $includes[] = 'phpstan-baseline-no-getExtras.neon'; } +if ($is_phpstan2) { + $includes[] = 'phpstan-baseline-phpstan2-only.neon'; +} + $config = []; $config['includes'] = $includes; return $config; diff --git a/src/Plugin/ProjectBrowserSource/SortHelper.php b/src/Plugin/ProjectBrowserSource/SortHelper.php index 7d3ffb696..c8be0eaec 100644 --- a/src/Plugin/ProjectBrowserSource/SortHelper.php +++ b/src/Plugin/ProjectBrowserSource/SortHelper.php @@ -48,12 +48,12 @@ final class SortHelper { } // If the first project is in the configured order but the second isn't, // the first one goes before the second one. - elseif (is_int($a_position) && $b_position === FALSE) { + elseif (is_int($a_position)) { return -1; } // If the first project isn't in the configured order but the second one // is, the second one goes before the first one. - elseif ($a_position === FALSE && is_int($b_position)) { + elseif (is_int($b_position)) { return 1; } // If neither project is in the configured order, leave them as-is. -- GitLab