Allow arbitrary data types for PHPStan compatibility in @return class methods

Created on 1 August 2023, over 1 year ago
Updated 31 May 2024, 6 months ago

Problem/Motivation

In Support advanced PHPStan data types (general, arrays) Fixed 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 , 📌 Refactor transactions Fixed

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

Closed: outdated

Version

8.3

Component

Coder Sniffer

Created by

🇮🇹Italy mondrake 🇮🇹

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

Comments & Activities

  • Issue created by @mondrake
  • 🇦🇺Australia alex.skrypnyk Melbourne

    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
    ----------------------------------------------------------------------
    
    
  • Status changed to Postponed: needs info 8 months ago
  • 🇳🇱Netherlands kingdutch

    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"];
      }
    
    }
    
  • Status changed to Closed: outdated 6 months ago
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    Closing as outdated.

Production build 0.71.5 2024