Problem/Motivation

#3253472: Support advanced PHPStan data types (general, arrays) introduced support for extended array specifications, but apparently multi-line array shapes are unsupported

Steps to reproduce

A docblock like this:

  /**
   * Returns an array with the driver's autoload information.
   *
   * [...]
   *
   * @return array{
   *     'autoload': string,
   *     'namespace': string,
   *     'dependencies': array<string, array{'autoload': string, 'namespace': string}>,
   *   }
   */
  public function getAutoloadInfo(): array {
   ...

which is parsed OK by PHPStan fails in coder with

----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 151 | ERROR | [x] Expected "array" but found "array{" for function
     |       |     return type
     |       |     (Drupal.Commenting.FunctionComment.InvalidReturn)
 152 | ERROR | [x] Return comment indentation must be 3 spaces, found
     |       |     5 spaces
     |       |     (Drupal.Commenting.FunctionComment.ReturnCommentIndentation)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Issue summary: View changes
mfb’s picture

This would be wonderful for documenting array shapes for function parameters as well. Those have some additional phpcs errors:

  • Parameter $options is not described in comment (Drupal.Commenting.FunctionComment.ParamMissingDefinition)
  • Missing parameter name (Drupal.Commenting.FunctionComment.MissingParamName)