Skip to content

Commit

Permalink
Merge pull request #3717 from axlon/invalid-return-never
Browse files Browse the repository at this point in the history
Fix `Squiz.Commenting.FunctionComment.InvalidNoReturn` false positive when return type is `never`
  • Loading branch information
jrfnl authored Jul 14, 2023
2 parents 276f68c + 6796215 commit 974c362
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
}
}
}//end if
} else if ($returnType !== 'mixed' && in_array('void', $typeNames, true) === false) {
// If return type is not void, there needs to be a return statement
// somewhere in the function that returns something.
} else if ($returnType !== 'mixed'
&& $returnType !== 'never'
&& in_array('void', $typeNames, true) === false
) {
// If return type is not void, never, or mixed, there needs to be a
// return statement somewhere in the function that returns something.
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
$endToken = $tokens[$stackPtr]['scope_closer'];
for ($returnToken = $stackPtr; $returnToken < $endToken; $returnToken++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,3 +1129,8 @@ public function variableCaseTest(
public function variableOrderMismatch($bar, $baz, $foo) {
return;
}

/**
* @return never
*/
function foo() {}
Original file line number Diff line number Diff line change
Expand Up @@ -1129,3 +1129,8 @@ public function variableCaseTest(
public function variableOrderMismatch($bar, $baz, $foo) {
return;
}

/**
* @return never
*/
function foo() {}

0 comments on commit 974c362

Please sign in to comment.