Problem/Motivation

Some @return, @param and @var type hints are missing the leading backslash (e.g.
the @return type hint of UserAuthenticationInterface::lookupAccount()). Phpstan doesn't like that.

Steps to reproduce

Proposed resolution

Add the missing leading backslash.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3559067

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

znerol created an issue. See original summary.

znerol’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Very straight forward.

mstrelan’s picture

Status: Reviewed & tested by the community » Needs review

There are at least two other instances like this:

$ grep -r "@return Drupal" core
core/modules/user/src/UserAuthenticationInterface.php:   * @return Drupal\User\UserInterface|false
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/AnnotationWithAttributes.php:     * @return Drupal\Tests\Component\Annotation\Doctrine\Fixtures\AnnotationTargetAll
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures/AnnotationWithRequiredAttributes.php:     * @return Drupal\Tests\Component\Annotation\Doctrine\Fixtures\AnnotationTargetAnnotation

I wonder if we should fix them here too?

There are a handful of params too:

$ grep -r "@param Drupal" core
core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php:   * @param Drupal\Tests\PerformanceData $performance_data
core/lib/Drupal/Core/Database/database.api.php: * @param Drupal\Core\Database\Query\AlterableInterface $query
core/lib/Drupal/Core/Database/database.api.php: * @param Drupal\Core\Database\Query\AlterableInterface $query
core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php:   * @param Drupal\Core\Theme\ActiveTheme $active_theme
core/modules/shortcut/shortcut.module: * @param Drupal\shortcut\ShortcutSetInterface $shortcut_set
core/modules/comment/comment.module: * @param Drupal\Core\Form\FormStateInterface $form_state
core/tests/Drupal/Tests/PerformanceTestTrait.php:   * @param Drupal\Core\Database\Event\DatabaseEvent $event

Setting NR to consider this, feel free to change back if there's a good reason not to fix them all.

znerol’s picture

Title: Fix UserAuthenticationInterface::lookupAccount @return type hint » Fix @return and @param type-hints with missing leading backslash
Issue summary: View changes
znerol’s picture

Title: Fix @return and @param type-hints with missing leading backslash » Fix type hints missing the leading backslash
Issue summary: View changes
mstrelan’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for those additions. Before anyone suggests a phpcs rule for this, the real answer is we should be on a reasonable phpstan level where these fail a build. I'm guessing these would be in level 5 or 6.

znerol’s picture

Had to revert the changes in core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures. These @var annotations are intentionally invalid.

quietone’s picture

Title: Fix type hints missing the leading backslash » Fix type hints missing the leading backslash in @param, @return and @var

  • quietone committed 693368f1 on 11.x
    docs: #3559067 Fix type hints missing the leading backslash in @param, @...

  • quietone committed 2474398f on 11.3.x
    docs: #3559067 Fix type hints missing the leading backslash in @param, @...
quietone’s picture

Version: 11.x-dev » 11.3.x-dev
Component: user system » other
Status: Reviewed & tested by the community » Fixed
Issue tags: +Coding standards

@znerol, thanks for fixing the test.

Committed to 11.x and cherry-pick to 11.3.x

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.