When hinting an array that can contain multiple types, FunctionCommentSniff gives a warning

class MyClass {

  /**
   *  @return (A|B)[]
   */
  public function foo() {}

}

Expected A|B[] but found (A|B)[] for function return type

This can be avoided by using the type hint A[]|B[] instead, but implies a slightly different meaning (an array containing only items of one of the types, versus containing items of either type).

PhpDocumentor: https://www.phpdoc.org/docs/latest/references/phpdoc/types.html#arrays

Comments

gapple created an issue. See original summary.

klausi’s picture

Status: Active » Postponed

This is a bit undefined in Drupal standards: https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...

Usually we don't use "()" characters at all in data types, that's why Coder complains. The question is whether we want to adopt phpdoc's version or not. So this probably needs a proposal and approval in the coding standards first, please file that in https://www.drupal.org/project/coding_standards

Thanks!