Problem/Motivation
Amongst the "new" errors found when running PHPStan on level 2 is: Variable $foo in PHPDoc tag @var does not exist.
This child-issue exists to fix the "low hanging fruit" ones.
Steps to reproduce
- Run PHPStan on level 2 and see the above error amongst all others.
Proposed resolution
- Solve all of the the above mentioned reported errors.
- Run PHPStan on level 2 and see less of the above mentioned error.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3323702
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:
- 3323702-fix-phpstan-l2
changes, plain diff MR !9751
Comments
Comment #2
spokjeComment #3
spokjeComment #4
spokjeA pre and post lvl2-baseline for 10.1.x-dev is attached.
Comment #5
spokjeComment #6
mondrakeI think in this case we should first check $tid is not empty, and return if it is. Then, load $term, and in this case we can keep the type hint, adding null to the signature. Then, return the final result. i.e.
Comment #7
malleziePutting needs work for #6.
I like this proposed change, makes things more readible.
Other changes look good.
Comment #8
_pratik_Comment #9
_pratik_I Hope this will work here.
Thanks
Comment #10
mallezieThanks @_pratik_
However instead of
I would adjust this to
This can be a single line comment for the var declaration.
Also checking for is_numeric is not needed here. This would be better typehinted on the method, but that's out of scope here.
Comment #11
_utsavsharma commentedMade changes as per the #10.
Please review.
Comment #12
spokjeMade all the changes as per the #10.
Please review.
Comment #13
spokjeComment #14
andypostThis type-hint is useless here, please revert the change and remove hint
this breaks logic, load() may return NULL but getChildren() expect entity
Comment #18
quietone commentedConverted to an MR and added a few more easy ones. The rest all require a bit more thought, so setting this for a review.
Comment #19
smustgrave commentedSeems like a good cleanup.
the 3 additions/moves of @var make sense to be added above the variables.
Comment #20
larowlanIs there something we can enable in our phpstan config or ignore entries we can remove here to prevent this coming back.
I'm wary of doing these in piecemeal chunks without a corresponding rule change to prevent it coming back - much like the approach we take for PHPCS
I've reviewed the parent issue and see that this was split to achieve some momentum, so in this case I'm ok with committing it, but ideally we'd be adding a rule or updating baselines etc to keep them from coming back.
Committed to 11.x
Thanks folks
Comment #23
mondrake@larowlan
that would be #3425412: [Sep 14, 2026] Bump PHPStan rule level to 3
Comment #24
larowlanCheers 👍