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.
Comments
Comment #3
klausiThanks 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!