Problem/Motivation

Drupal.Commenting.FunctionComment.InvalidReturnNotVoid is performing a task that PHPStan should perform on level 3. Additionally the PHPCS rule is not smart enough and gets confused by code like:

/**
 * Some array returning function.
 *
 * @return array
 *   Some array.
 */
function returnSomeArray(): array {
  do_something_with_a_callback(function () {
     if ($some_condition) {
       // Early return.
       return;
     }
     
     // Do work.
   });
   return [];
}

it'll throw an error on the early return, not understanding that it's not part of the outer function.

Steps to reproduce

Proposed resolution

Remove the rule, return type checking is not a coding style rule but a job for PHPStan.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Kingdutch created an issue. See original summary.

  • klausi authored 24bad887 on 8.3.x
    fix(FunctionComment): Ignore return statements in closures (#3427690)
    
    
klausi’s picture

Category: Feature request » Bug report
Status: Active » Fixed

Thanks for reporting!

We don't need to throw out this check, we can modernize if from the upstream Squiz standard which already implemented closure support.

It was a bit of a riddle to figure out, but thanks to our test cases I got it working: https://github.com/pfrenssen/coder/pull/223

I had to disable one test that did even a bit more semantics checking, which should really be done by phpstan.

And merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.