diff --git a/SlevomatCodingStandard/Sniffs/Commenting/UselessFunctionDocCommentSniff.php b/SlevomatCodingStandard/Sniffs/Commenting/UselessFunctionDocCommentSniff.php index 8476b568b..1f48a16b7 100644 --- a/SlevomatCodingStandard/Sniffs/Commenting/UselessFunctionDocCommentSniff.php +++ b/SlevomatCodingStandard/Sniffs/Commenting/UselessFunctionDocCommentSniff.php @@ -11,6 +11,7 @@ use SlevomatCodingStandard\Helpers\SniffSettingsHelper; use SlevomatCodingStandard\Helpers\SuppressHelper; use SlevomatCodingStandard\Helpers\TokenHelper; +use function array_key_exists; use function array_map; use function in_array; use function sprintf; @@ -73,6 +74,10 @@ public function process(File $phpcsFile, $functionPointer): void $parametersAnnotations = FunctionHelper::getValidParametersAnnotations($phpcsFile, $functionPointer); foreach ($parametersAnnotations as $parameterName => $parameterAnnotation) { + if (!array_key_exists($parameterName, $parameterTypeHints)) { + return; + } + if (!AnnotationHelper::isAnnotationUseless($phpcsFile, $functionPointer, $parameterTypeHints[$parameterName], $parameterAnnotation, $this->getTraversableTypeHints())) { return; } diff --git a/tests/Sniffs/Commenting/data/uselessFunctionDocCommentSniffNoErrors.php b/tests/Sniffs/Commenting/data/uselessFunctionDocCommentSniffNoErrors.php index 5f73e1610..d3941f5a1 100644 --- a/tests/Sniffs/Commenting/data/uselessFunctionDocCommentSniffNoErrors.php +++ b/tests/Sniffs/Commenting/data/uselessFunctionDocCommentSniffNoErrors.php @@ -167,4 +167,13 @@ public function withAnotherAnnotation(int $a): bool return true; } + /** + * @param int $aaaaa + * @return bool + */ + public function wrongParameterNameInAnnotation(int $a): bool + { + return true; + } + }