Problem/Motivation

In #3161129: [PP-1] Fix phpdoc return type for RouteProvider::getAllRoutes() we're trying to document the @return value of a function that returns an \Iterator. For good reason, we like to be specific. Apparently, phpdoc now supports a syntax for defining the type of the values (and optionally, keys) in an an array or Iterator. It's something like this:

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

However, we don't currently do this anywhere, and Coder doesn't understand this syntax yet (see #3347758: [PP-1] Support the recommended phpdoc syntax for documenting Iterator return types).

So we need to discuss if this is the right thing, decide on the appropriate style for it (e.g. do we put the space after the comma?), etc.

Steps to reproduce

Proposed resolution

When documenting collections (eg Iterator and friends), allow using the <keyType, valueType> syntax to define the types of the keys and values.

If the keys don't matter, you can just use the valueType like so:
<valueType>

Remaining tasks

User interface changes

API changes

Data model changes

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

    dww created an issue. See original summary.

    dww’s picture

    Title: Adopt the phpdoc standard for documenting Iterator key and value types » Adopt the phpdoc standard for documenting collection (eg Iterator) key and value types
    Issue summary: View changes

    Thanks, good point! Minor updates to title and summary to capture that.

    drunken monkey’s picture

    Yes, please!
    I’d definitely put a space after the comma. That’s also the style used in all of @andypost’s links.

    mglaman’s picture

    mondrake’s picture

    and to #3309010: Support PHPDoc Types in @param @var @return annotations...

    Hopefully one day we can start using them and stop opening issues to use them :)

    In any case we can use @phpstan-return annotations already now without sniff failures happening. See #2664570: Move Attribute classes under Drupal\Component and MR!141.

    andypost’s picture

    dww’s picture

    Status: Needs review » Closed (duplicate)
    Related issues: +#3309010: Support PHPDoc Types in @param @var @return annotations

    Yeah, this is duplicate. 😅 I hadn't found the related issues when searching. Moving to #3309010: Support PHPDoc Types in @param @var @return annotations now. Thanks, everyone!