Issue summary generated with the help of an LLM.
Problem/Motivation
PHPStan currently flags several varTag.differentVariable errors across Drupal core where an inline @var PHPDoc tag specifies a variable name that does not match the actual variable being assigned (for example: "Variable $foo in PHPDoc tag @var does not match assigned variable $bar."). These errors are currently ignored in core/.phpstan-baseline.php.
When the variable name in a @var annotation does not match the assigned variable—typically due to variable renames or copy-paste mistakes—static analysis tools and IDEs ignore the type hint completely, reducing type safety and code clarity.
Proposed resolution
- Update all
@varPHPDoc annotations flagged withvarTag.differentVariableso the documented variable name matches the assigned variable (or remove obsolete/redundant@vartags where appropriate). - Regenerate
core/.phpstan-baseline.phpto remove the resolvedvarTag.differentVariableentries.
Remaining tasks
- Fix all
varTag.differentVariableoccurrences in core. - Regenerate
core/.phpstan-baseline.php. - Verify PHPStan passes in GitLab CI.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork drupal-3640904
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
Comment #2
longwaveComment #3
mallezieComment #5
mallezieComment #6
tobiasbI left 2 comments I just reviewed it via Gitlab-UI.
Comment #7
mallezieThank you, i've added the the new var suggestions. While pure theoretically not in scope, those fix 2 new phpstan errors.
The removed workflow_type var comment was not needed anymore, since the getTypePlugin already reports to return a \Drupal\workflows\WorkflowTypeInterface
Leaving issue in needs review, and marked the comments as resolved.
Comment #8
tobiasbI thought those were just typos as I saw this :D:
Comment #9
tobiasb