Skip to content

Commit 201bce0

Browse files
committed
Fix bug in ReturnTypeDeclarationSniff
1 parent d74cb03 commit 201bce0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ private function maybeErrors(
121121
*/
122122
private function returnTypeInfo(File $file, int $functionPosition, int $functionEnd): array
123123
{
124-
$returnType = $file->findNext(
125-
T_RETURN_TYPE,
126-
$functionPosition + 3, // open parenthesis, close parenthesis, colon
124+
$returnTypeToken = $file->findNext(
125+
[T_RETURN_TYPE],
126+
$functionPosition + 3, // 3: open parenthesis, close parenthesis, colon
127127
$functionEnd - 1
128128
);
129129

130+
$returnType = $file->getTokens()[$returnTypeToken] ?? null;
131+
if ($returnType && $returnType['type'] !== "T_RETURN_TYPE") {
132+
$returnType = null;
133+
}
134+
130135
$hasNonVoidReturnType = $returnType && $returnType['content'] !== 'void';
131136
$hasVoidReturnType = $returnType && $returnType['content'] === 'void';
132137
$hasNoReturnType = !$returnType;

0 commit comments

Comments
 (0)