Problem/Motivation

My core development environment is running on PHP 8.5. When backporting an issue to 11.x or 11.4.x I try to run composer run phpstan-baseline, but it introduces new violations not applicable to PHP 8.3. To avoid this we can specify the php version in phpstan.neon.dist

Steps to reproduce

Run phpstan on php8.5 against 11.4.x and get 50 new errors

Proposed resolution

  • Add phpVersion: 80500 to the parameters section of phpstan.neon.dist for main
  • Add phpVersion: 80300 for 11.x and 11.4.x
  • Continue to bump the version in line with the php version that gitlab ci runs on

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3605599

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

Status: Active » Needs review
Issue tags: +PHPStan
mstrelan’s picture

Issue summary: View changes

Interesting to note that gitlab runs these jobs on PHP 8.5 and correct detects the php version:

PHP runtime version: 8.5.7
PHP version for analysis: 8.3 (from config.platform.php in composer.json)

Regardless, this still helps my (and likely others) local environments.

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

According to the docs this should work as intended: https://phpstan.org/config-reference#phpversion

If you want to analyse a codebase as if it was written for a different PHP version than you’re currently running, change the phpVersion parameter:

RTBC (assuming 11.x random fail goes green).

mstrelan’s picture

FWIW the root cause in my local environment was because it's using a composer overlay (composer.local.json) so phpstan couldn't read the correct platform value. I've opened a PR at https://github.com/amateescu/ddev-drupal-dev/pull/24 to address that, but if other developers have different setups they could still benefit from this change in core.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Can we add a unit test to ensure this stays in sync with the version in composer.json and/or the minimum PHP version constant?

mstrelan’s picture

Status: Needs work » Needs review

I added to an existing composer test, not sure if there is a better place.

dcam’s picture

I'm OK with the assertions staying in the Composer test, but we do have separate test directories in Core/tests/Drupal/Tests for CSpell and PHPCS. Maybe PHPStan ought to have one too.