Skip to content

Commit 974c362

Browse files
authored
Merge pull request #3717 from axlon/invalid-return-never
Fix `Squiz.Commenting.FunctionComment.InvalidNoReturn` false positive when return type is `never`
2 parents 276f68c + 6796215 commit 974c362

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
143143
}
144144
}
145145
}//end if
146-
} else if ($returnType !== 'mixed' && in_array('void', $typeNames, true) === false) {
147-
// If return type is not void, there needs to be a return statement
148-
// somewhere in the function that returns something.
146+
} else if ($returnType !== 'mixed'
147+
&& $returnType !== 'never'
148+
&& in_array('void', $typeNames, true) === false
149+
) {
150+
// If return type is not void, never, or mixed, there needs to be a
151+
// return statement somewhere in the function that returns something.
149152
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
150153
$endToken = $tokens[$stackPtr]['scope_closer'];
151154
for ($returnToken = $stackPtr; $returnToken < $endToken; $returnToken++) {

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,8 @@ public function variableCaseTest(
11291129
public function variableOrderMismatch($bar, $baz, $foo) {
11301130
return;
11311131
}
1132+
1133+
/**
1134+
* @return never
1135+
*/
1136+
function foo() {}

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,8 @@ public function variableCaseTest(
11291129
public function variableOrderMismatch($bar, $baz, $foo) {
11301130
return;
11311131
}
1132+
1133+
/**
1134+
* @return never
1135+
*/
1136+
function foo() {}

0 commit comments

Comments
 (0)