Problem/Motivation

In #3253472: Support advanced PHPStan data types (general, arrays) we relaxed data type requirements for @param and @return data types.

However it is still failing

Steps to reproduce

https://www.drupal.org/pift-ci-job/2730350, #3364706: Refactor transactions

 91 | ERROR | [x] Expected "array<stringStackItemType>" but found
    |       |     "array<string,StackItemType>" for function return
    |       |     type
    |       |     (Drupal.Commenting.FunctionComment.InvalidReturn)

Comments

mondrake created an issue. See original summary.

alex.skrypnyk’s picture

I'm experiencing the same on this simple example

/**
 * Get fields from the form without hidden fields.
 *
 * @param array $form
 *   Form array.
 *
 * @return array<string, mixed>
 *   Array of fields.
 *
 * @SuppressWarnings(PHPMD.StaticAccess)
 */

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 236 | ERROR | Return type "array<string, mixed>" must not contain
     |       | spaces
----------------------------------------------------------------------

When spaces removed, I'm getting another error:

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 236 | ERROR | [x] Expected "arraystringmixed" but found
     |       |     "array<string,mixed>" for function return type
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

kingdutch’s picture

Status: Active » Postponed (maintainer needs more info)

I'm unable to reproduce this against the latest version of PHPCS.

class SniffTest {

  /**
   * Kitchen sink test.
   *
   * @return array<string, mixed>
   *   Array of results.
   */
  public function kitchenSink() : array {
    return ["result" => "foo"];
  }

}
klausi’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Closing as outdated.