Skip to content

Commit 85e3329

Browse files
committed
UselessFunctionDocCommentSniff: Fixed internal error
1 parent dc5a270 commit 85e3329

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

SlevomatCodingStandard/Sniffs/Commenting/UselessFunctionDocCommentSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
1212
use SlevomatCodingStandard\Helpers\SuppressHelper;
1313
use SlevomatCodingStandard\Helpers\TokenHelper;
14+
use function array_key_exists;
1415
use function array_map;
1516
use function in_array;
1617
use function sprintf;
@@ -73,6 +74,10 @@ public function process(File $phpcsFile, $functionPointer): void
7374
$parametersAnnotations = FunctionHelper::getValidParametersAnnotations($phpcsFile, $functionPointer);
7475

7576
foreach ($parametersAnnotations as $parameterName => $parameterAnnotation) {
77+
if (!array_key_exists($parameterName, $parameterTypeHints)) {
78+
return;
79+
}
80+
7681
if (!AnnotationHelper::isAnnotationUseless($phpcsFile, $functionPointer, $parameterTypeHints[$parameterName], $parameterAnnotation, $this->getTraversableTypeHints())) {
7782
return;
7883
}

tests/Sniffs/Commenting/data/uselessFunctionDocCommentSniffNoErrors.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,13 @@ public function withAnotherAnnotation(int $a): bool
167167
return true;
168168
}
169169

170+
/**
171+
* @param int $aaaaa
172+
* @return bool
173+
*/
174+
public function wrongParameterNameInAnnotation(int $a): bool
175+
{
176+
return true;
177+
}
178+
170179
}

0 commit comments

Comments
 (0)