Problem/Motivation

The phpstan job reports 2 errors, both drupal.entityStoragePropertyAssignment, Storing entity storage as a class property is not recommended. The job is allow-failure, so pipelines still show green overall, but the warning is permanent. It was green on 3.x in June at the same commit, so this is phpstan-drupal ruleset drift rather than a code regression. Spotted on the pipeline of #3613716: Add a Domain Render Context submodule to render out-of-band output in another domain's context.

  • domain_config_extras/src/DomainConfigUtilities.php line 38: the domain storage is assigned to a property in the constructor.
  • domain_sso_admin_toolbar/tests/src/Kernel/DomainSwitchControllerTest.php line 60: the same, assigned in setUp().

Beyond the warning, a storage handler captured once outlives a container rebuild (a module install or uninstall, or a kernel test rebuilding the container mid-test), so the held object can be stale. The test above does rebuild the container in setUp().

Proposed resolution

Replace the property with a protected domainStorage() accessor calling EntityTypeManagerInterface::getStorage() at the call site, the shape Domain itself adopted in its own storage-getter cleanup. In DomainConfigUtilities the constructor promotes the entity type manager instead, so the class keeps one dependency and no separate assignment.

Remaining tasks

Apply both, keep phpcs and phpunit green.

User interface changes

None.

API changes

None for consumers. DomainConfigUtilities loses the protected $domainStorage property and gains a protected domainStorage() method; its constructor parameter is renamed and promoted, which is autowired and needs no services.yml change.

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

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review

  • mably committed 837a48c6 on 3.x
    task: #3613722 Fix PHPStan: do not store entity storage as a class...

  • mably committed 7b1abb12 on 2.0.x
    task: #3613722 Fix PHPStan: do not store entity storage as a class...
mably’s picture

Status: Needs review » Fixed

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.