Issue summary generated with the help of an LLM.
Problem/Motivation
PHPStan currently flags several return.phpDocType errors across Drupal core where a @return PHPDoc annotation specifies a type that is incompatible with—or not a subtype of—the method or function's native PHP return type declaration (for example: "PHPDoc tag @return with type Foo is not subtype of native type Bar."). These errors are currently ignored in core/.phpstan-baseline.php.
When a @return docblock contradicts a native return type, PHPStan discards the PHPDoc type information, reducing static analysis accuracy and causing confusion for developers and IDEs.
Proposed resolution
- Review all methods and functions flagged with
return.phpDocTypeand align their@returnPHPDoc annotations with their native return types (or remove redundant/incorrect@returntags where the native return type already provides complete type information). - Regenerate
core/.phpstan-baseline.phpto remove the resolvedreturn.phpDocTypeentries.
Remaining tasks
- Fix all
return.phpDocTypeoccurrences 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-3641449
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 #3
mallezieThis MR, fixes all occurences of that phpstan error.
2 approaches done here:
* In some cases removed the phpdoc return when it had no value.
* In other cases the return statement in phpdocs was update to match the real return type.
One notable case was core/modules/language/src/Form/ContentLanguageSettingsForm.php
There the return type of the function was changed, as there that was incorrect.
Comment #4
mstrelan commentedLeft a few comments, I think we should reduce the scope slightly to make this dead-simple to approve.