Problem/Motivation

The phpstan-drupal package update on 2026-07-14 introduced new lint rules that flag 32 pre-existing code patterns in Patternkit. The 9.1.x branch passed PHPStan on 2026-07-13 and now fails with 32 errors. None of the violations were introduced by any recent code change to 9.1.x.

This is a contributor-facing regression: any MR opened against 9.1.x will fail PHPStan CI until this issue is resolved.

The phpstan-drupal package update introduced rules in the following categories:

  • drupal.entityStoragePropertyAssignment (17 occurrences): entity storage stored as a class property instead of resolved at call site
  • drupal.entityStorageDirectInjection (5 occurrences): entity storage injected directly instead of via EntityTypeManager
  • method.deprecatedClass / classConstant.deprecatedClass (14 occurrences): references to ReusableBlockHooks, deprecated in 9.1.2
  • return.type (4 occurrences): return type mismatches in PatternUsageManager
  • dependencySerializationTraitProperty.unsupportedReadOnlyProperty (1 occurrence): readonly property incompatible with DependencySerializationTrait
  • dependencySerializationTraitProperty.unsupportedPrivateProperty (1 occurrence): private property incompatible with DependencySerializationTrait
  • nonAbstractTestClass.NameNoSuffixTest (1 occurrence): test base class name lacks a Test suffix and is not abstract
  • Other (3 occurrences): staticMethod.deprecated, globalDrupalDependencyInjection.useDependencyInjection, encapsedStringPart.nonString

The affected files span the main module and the patternkit_usage_tracking submodule. All violations are pre-existing. The new rules expose long-standing patterns rather than any new code.

Proposed resolution

Each violation category requires individual assessment before deciding between an inline fix or a justified baseline entry.

The recommended approach:

  1. Fix violations that are safe and low-risk to correct inline. The deprecated ReusableBlockHooks references and the test class naming issue are good candidates.
  2. Baseline violations where the fix requires architectural changes that are outside the scope of a CI hotfix. The entityStoragePropertyAssignment patterns across 17 locations fall into this category.
  3. Document the rationale for each baseline entry in the phpstan baseline file so future contributors understand why the suppression exists.
  4. Open follow-up issues for baselined violations that represent real improvement opportunities.

This keeps the CI unblocked while avoiding untested architectural changes being bundled into a hotfix.

Remaining tasks

  • Assess each of the 32 violations and decide: fix inline or baseline with rationale
  • Update the phpstan baseline file
  • Verify PHPStan CI passes on 9.1.x
  • Open follow-up issues for any baselined violations that warrant separate tracking
  • Link any follow-up issues to this issue

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

PHPStan CI now passes on 9.1.x after updating the phpstan baseline to account for new rules introduced by the phpstan-drupal package update. Violations safe to fix inline were corrected; remaining violations were baselined with documented rationale and tracked in follow-up issues.

Issue fork patternkit-3612106

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

slucero created an issue. See original summary.

yusuf_khan made their first commit to this issue’s fork.

yusuf_khan’s picture

i'm working on this

yusuf_khan’s picture

Status: Active » Needs review

@slucero I have applied the Proposed resolution and Fixed PHPStan failures caused by phpstan-drupal update .Please review the MR.

yusuf_khan’s picture

Status: Needs review » Needs work

@slucero Please advise on the failing php unit , i try to fix but its still failing

slucero’s picture

@yusuf_khan, thank you for your work on this! The MR looks great so far. I've noted a few minor revisions to make throughout if you don't mind. For the PHPUnit failures, I believe that will be fixed by the suggestion changing the test's URL target.

I also created and linked the two follow-up issues for the items being baselined if you wouldn't mind including reference to those in the doc block for it:

  • slucero committed 1e15c19e on 9.1.x authored by yusuf_khan
    fix: #3612106 PHPStan CI fails on 9.1.x after phpstan-drupal package...
slucero’s picture

Status: Needs work » Fixed

@yusuf_khan, since this was blocking CI on other open MRs I've opted to go ahead and implement the changes directly on top of the work you've already completed. Everything seems to be working now and I greatly appreciate your contribution! Thank you.

This has now been merged into 9.1.x for inclusion in the 9.1.3 release.
See #3542304: Patternkit 9.1.3 Release Plan.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • slucero committed 1e15c19e on ddev-development-docs authored by yusuf_khan
    fix: #3612106 PHPStan CI fails on 9.1.x after phpstan-drupal package...