[PP-1] Support the recommended phpdoc syntax for documenting Iterator return types

Created on 14 March 2023, almost 2 years ago
Updated 28 March 2023, over 1 year ago

Duplicate with ✨ Support advanced PHPStan data types (general, arrays) Fixed which solves a superset of this problem.

Problem/Motivation

πŸ› [PP-1] Fix phpdoc return type for RouteProvider::getAllRoutes() Postponed is trying to fix some core phpdoc comments about Iterator return types.
Unfortunately, coder doesn't recognize the valid syntax:

@return \Iterator<string, \Symfony\Component\Routing\Route>

It instead complains this is invalid, and suggests the following, broken thing, instead:

@return \Iteratorstring\Symfony\Component\Routing\RouteCollection

Steps to reproduce

Check out the testbot results from https://www.drupal.org/pift-ci-job/2592851 β†’

FILE: ...www/html/core/lib/Drupal/Core/Routing/RouteProviderInterface.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 97 | ERROR | [x] Expected
    |       |     "\Iteratorstring\Symfony\Component\Routing\Route"
    |       |     but found
    |       |     "\Iterator<string,\Symfony\Component\Routing\Route>"
    |       |     for function return type
    |       |     (Drupal.Commenting.FunctionComment.InvalidReturn)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Proposed resolution

Teach coder how to understand the valid syntax.

Remaining tasks

Get community agreement on the right way to format this syntax #3348310: Adopt the phpdoc standard for documenting collection (eg Iterator) key and value types β†’
Change FunctionCommentSniff.php to allow the new syntax, probably by enhancing suggestType() to know about it.

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Closed: duplicate

Version

8.3

Component

Coder Sniffer

Created by

πŸ‡ΊπŸ‡ΈUnited States dww

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024