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.phpDocType and align their @return PHPDoc annotations with their native return types (or remove redundant/incorrect @return tags where the native return type already provides complete type information).
  • Regenerate core/.phpstan-baseline.php to remove the resolved return.phpDocType entries.

Remaining tasks

  • Fix all return.phpDocType occurrences 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

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

mallezie created an issue. See original summary.

mallezie’s picture

Status: Reviewed & tested by the community » Needs review

This 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.

mstrelan’s picture

Status: Needs review » Needs work

Left a few comments, I think we should reduce the scope slightly to make this dead-simple to approve.