phpstan dev constraints make it difficult for modules to support 11.2 and below

Created on 26 June 2025, 10 days ago

Problem/Motivation

๐Ÿ“Œ Update PHPStan to 2.1.17 Active tightened the constraints for phpstan/phpstan mglaman/phpstan-drupal and phpstan/phpstan-phpunit that forces 2.x on 11.2. This means that contrib projects that have custom phpstan configs and/or ignores cannot get passing CI pipelines on both 11.2 and 11.1 (and earlier).

This is because some configs and the ignore syntax differs between the 2 versions. You can see an example here for the Diff module https://git.drupalcode.org/project/diff/-/jobs/5639940

In this pipeline, even though I've allowed 1.x and 2.x in Diff's composer.json (so that the composer (next minor) can pass), phpstan fails because some config no longer exists:

Unexpected item 'parameters โ€บ strictRules โ€บ strictCalls'.

If I were to change this then I could no longer run phpstan against 11.1 (phpstan 1.x)

Steps to reproduce

Setup a contrib module with a phpstan config like this https://git.drupalcode.org/project/diff/-/blob/2.x/phpstan.neon?ref_type... or many other ways.

Proposed resolution

Allow both 1.x and 2.x again in core's constraints.

Remaining tasks

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

other

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia acbramley

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @acbramley
  • Merge request !12510Issue #3532698: Relax phpstan constraints โ†’ (Closed) created by acbramley
  • Pipeline finished with Failed
    10 days ago
    Total: 101s
    #532652
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    ๐Ÿ“Œ Update PHPStan to 2.1.17 Active is where the 1.x version was removed by accident

  • Pipeline finished with Success
    10 days ago
    Total: 1097s
    #532660
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Major, I think. Maybe not quite critical?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    This is where if we had a tooling topic maintainer I would ask them for signoff. In lieu of that, I guess framework managers?

    Do we need to validate the 1.x constraint with an affected contrib module somehow, since core won't run pipelines with it?

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    I don't think there's a way to test this without committing it, but also nothing can go very wrong.

    Not sure how much this is going to help though if phpstan 1 and 2 fail on each other's config but perhaps I'm misunderstanding.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    Dumb questions... why do we have to put phpstan/phpstan as a dev dependency in composer.json, and therefore lock it for install, at all?

    Can't we just omit that and let CI jobs do their own composer require when they need the tool, for whatever version they care for? And no metapackage locks either. Also, quicker composer installs and less data - only get package when needed.

    Then maybe OK, we may want to specify conflict versions in composer.json to avoid running with obsoleted baseline, but that makes a lot of difference than always forcing a download.

    My 0.02$.

  • Merge request !12525no-composer.json โ†’ (Closed) created by mondrake
  • Pipeline finished with Failed
    9 days ago
    #533256
  • Pipeline finished with Failed
    9 days ago
    Total: 64s
    #533263
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    MR!12525 has #7 in practice.

  • Pipeline finished with Success
    9 days ago
    #533271
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    It would mean you can't composer install core and run phpstan on it, you'd always have to composer require it first, I don't see why we can't specify our own dev dependencies as actual dependencies really.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cmlara

    โœจ Create metapackage of (loose) contrib test dependencies Active touches on the comments from #7 and #10 in that we ultimately don't have a good package for "developing contrib" vs "developing core" to pull dependencies. For contrib the phpstan constraint really is not needed.

    Long term I do suggest Core consider if they even need a package for "developing core" package. The core composer.json should be able to load everything a developer needs to test core meaning there really is only a need for listing what is needed by contrib to use Core as a test platform.

    To me: Visually MR!12510 change looks fine.

    Biggest risk of doing this is some downstream dependency lists PHPStan (or related modules) as a regular dependency instead of a dev dependency forcing back to ^1, or some other sub-dependency of PHPStan (or related modules) is somehow forced back to a version only supported on older releases. Both of those will however likely fail the jobs (baseline not matching) so will be know very quickly, and if that does occur the ^2 constraint alone would fail the Composer stage meaning both scenarios require interaction by the Core team to resolve. MR!12525 would suffer the same risk.

    Essentially the risk to core is minimal, and would generally just show up at a different stage.

    Linking ๐Ÿ› Can't update to 11.2.0 Active for cross-issue visibility (on Slack there was originally some discussion of using that issue to handle this concern).

  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cmlara

    Bot is only testing MR!12525.

    That said it may be legitimate tooling failure as it would change the tooling requirements.

    Back to NR for MR!12510, if it werenโ€™t for the required FM sign off I would call it RTBC.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    mondrake โ†’ changed the visibility of the branch 3532698-no-composer-dev to hidden.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly mondrake ๐Ÿ‡ฎ๐Ÿ‡น

    Closed MR!12525.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Yeah 12525 is interesting but way out of scope; let's explore more in @cmlara's related issue.

    @cmlara, issues can be RTBC with the "Needs $foo review" tags when $foo is a committer role, especially if the issue is otherwise RTBC, because the RTBC queue is the list of issues committers review. :) So setting RTBC based on @cmlara's comment (not my own knowledge).

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    I think relaxing the constraint is fine, it's not entirely clear to me from the issue summary whether phpstan 10 and 11 have mutually exclusive configurations or whether it's only the constraint that's the problem - but we can't do much about the mutually exclusive configurations if that's a problem anyway.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Alright then.

    We probably want a change record then though?

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    I don't think it needs a change record - we're widening a constraint that was only in a couple of patch releases - everything will automatically start to work for modules it was broken on, modules that already updated to phpstan 2 don't need to downgrade again.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    OK, let's split the difference at a small release note in the patch release, which I've added to the IS.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    Also confirmed the issue with the original more open constraint had no CR.

    • larowlan โ†’ committed 67ac0681 on 11.2.x
      Issue #3532698 by mondrake, acbramley, xjm, catch, cmlara: phpstan dev...
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    Thanks all, committed to 11.x and backported to 11.2.x

Production build 0.71.5 2024