Issue #3612201: Fix phpstan: Storing entity storage as a class property is not recommended

Fixes the two new phpstan-drupal rules from the EntityHandlerDirectInjectionRule family (phpstan-drupal#686):

  • drupal.entityStoragePropertyAssignment -- "Storing entity storage as a class property is not recommended"
  • drupal.entityStorageDirectInjection -- "Direct injection of entity storage ... is not recommended"

Entity storage handlers are no longer cached in class properties nor injected through constructors. Each class now injects EntityTypeManagerInterface and exposes a small protected xStorage() getter that calls getStorage() at the call-site, matching the existing DomainResolver::domainStorage() pattern. Storages that were only injected/stored but never used were dropped.

Why 4.x

Three public (non-@internal) base classes turn a protected storage-cache property into a protected getter method, which is an API change for external subclasses:

  • DomainControllerBase
  • DomainElementManager
  • DomainBlockBase

Every other change is on an @internal class or is a constructor-signature change (constructors are excluded from Drupal's BC policy), so it is BC-safe. A BC-safe subset (no property removals on those base classes) will be backported to 3.x, 3.0.x and 2.0.x.

Verification

  • Both storage rules: 0 violations.
  • No new phpstan errors introduced (verified against baseline).
  • phpcs clean on all changed files.
  • Kernel test suites pass locally.

Merge request reports

Loading