Report the deprecated original property on values typed as EntityInterface
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- drupal, php
- Domain
- devtools, testing-qa
Research direction
Start by reading the existing deprecation handling in EntityFieldReflection and the rules that skip DeprecationHelper::backwardsCompatibleCall() callbacks. Add a rule for PropertyFetch nodes named original, checking entity subtypes on Drupal 11.2 and later and distinguishing reads, isset(), assignments, and unset(). Cover entity types without duplicate reports from EntityFieldReflection; done means the proposed accesses are reported correctly and compatible calls are skipped.
Written by the indexing model from the issue text.
Description
#1076 reports the deprecated original property through EntityFieldReflection. That covers values typed as a content entity class, ContentEntityInterface, or a config entity class. It misses the most common case:
function mymodule_entity_presave(EntityInterface $entity): void {
if ($entity->original->label() !== $entity->label()) {
// ...
}
}
PHPStan only asks property reflection extensions about an interface when the interface is in universalObjectCratesClasses. ContentEntityInterface is there, but EntityInterface and ConfigEntityInterface aren't. Adding them would allow any property on config entities, so that isn't an option.
hook_entity_presave(), hook_entity_update(), and entity event subscribers all receive EntityInterface. That's where most code reads original, and it breaks on Drupal 12 without a warning.
Proposal
Add a rule that checks ->original directly instead of going through property reflection:
- Report
PropertyFetchnodes namedoriginalwhen the variable's type is a subtype ofEntityInterface, on Drupal 11.2 and later. - Tell reads and
isset()apart from assignments andunset(). Core recommendsgetOriginal()for the first two andsetOriginal()for the others. A property reflection can't make that distinction. - Skip code inside
DeprecationHelper::backwardsCompatibleCall()callbacks, like other deprecations.
If the rule covers every entity type, #1076's deprecation in EntityFieldReflection can be removed so the same access isn't reported twice.
- Dominant language
- PHP
- Stars
- 208
- Forks
- 88
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 15
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mglaman/phpstan-drupal
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
mglaman/phpstan-drupal#1078 ·
Maintainers usually reply within 1 day
-
Report constraint plugins that break on Drupal 12 because they have no named-arguments constructorPossibly taken @goba claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
mglaman/phpstan-drupal#1075 ·
Maintainers usually reply within 1 day
-
Magic properties: original on entities, name on UserSession and password on User are not reported as deprecatedPossibly taken @goba claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
mglaman/phpstan-drupal#1074 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
mglaman/phpstan-drupal#1051 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
mglaman/phpstan-drupal#1047 ·
Maintainers usually reply within 1 day
All issues in mglaman/phpstan-drupal
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-sitemap#125 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
nikic/PHP-Parser#1184 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
api-platform/core#8835 ·
Maintainers usually reply within 2 days
-
14.3.x
Difficulty 1/5 1-3 hours Newbie friendliness 82/100