Problem/Motivation

Method "Doctrine\Common\Annotations\Reader::getClassAnnotations()" will return "array" as of its next major version. Doing the same in implementation "Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader" will be required when upgrading.

Method "Doctrine\Common\Annotations\Reader::getMethodAnnotations()" will return "array" as of its next major version. Doing the same in implementation "Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader" will be required when upgrading.

Method "Doctrine\Common\Annotations\Reader::getPropertyAnnotations()" will return "array" as of its next major version. Doing the same in implementation "Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader" will be required when upgrading.

Method "Doctrine\Common\Annotations\Reader::getClassAnnotation()" will return "?T" as of its next major version. Doing the same in implementation "Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader" will be required when upgrading.

Method "Doctrine\Common\Annotations\Reader::getMethodAnnotation()" will return "?T" as of its next major version. Doing the same in implementation "Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader" will be required when upgrading.

Method "Doctrine\Common\Annotations\Reader::getPropertyAnnotation()" will return "?T" as of its next major version. Doing the same in implementation "Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader" will be required when upgrading.

Steps to reproduce

Proposed resolution

Add the type hints.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3231693-2.patch3.01 KBdaffie

Comments

daffie created an issue. See original summary.

daffie’s picture

Status: Active » Needs review
StatusFileSize
new3.01 KB

In core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php on line #144-145 we have the code:

/** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass(), $this->pluginDefinitionAnnotationName)) {

I have taken that as the return value for the 3 methods that get the type hint: ?T.

longwave’s picture

I am not sure this is right. I guess this is the Symfony debug class loader reading the docblock for the Doctrine classes and making an assumption that because there are @return with class declarations, a return type will be added - but has Doctrine actually announced this?

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Needs review » Postponed

Marking as postponed, as I believe this is a false positive caused by the over-eager DebugClassLoader reading docblocks in third party code and assuming they mean that typehints will be added.

gábor hojtsy’s picture

Status: Postponed » Active
longwave’s picture

I still think this is a false positive and hence should be won't fix. There is no guarantee that:

  1. upstream will add the return type in their next major version
  2. upstream's docblock is currently 100% correct about the existing return type
catch’s picture

Status: Active » Closed (duplicate)