Skip to content

Commit e7fb4ea

Browse files
committed
Ignore invalid annotations in TypeHintDeclarationSniff
1 parent df75233 commit e7fb4ea

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private function checkUselessDocComment(\PHP_CodeSniffer_File $phpcsFile, int $f
440440
}
441441

442442
foreach (FunctionHelper::getParametersAnnotations($phpcsFile, $functionPointer) as $parameterAnnotation) {
443-
if (preg_match('~^\\S+\\s+(?:(?:\.{3}\\s*)?\$\\S+\\s+)?[^$]~', $parameterAnnotation->getContent())) {
443+
if ($parameterAnnotation->getContent() !== null && preg_match('~^\\S+\\s+(?:(?:\.{3}\\s*)?\$\\S+\\s+)?[^$]~', $parameterAnnotation->getContent())) {
444444
return;
445445
}
446446
}
@@ -694,6 +694,10 @@ private function getFunctionParameterTypeHintsDefinitions(\PHP_CodeSniffer_File
694694
$parametersNames = FunctionHelper::getParametersNames($phpcsFile, $functionPointer);
695695
$parametersTypeHintsDefinitions = [];
696696
foreach (FunctionHelper::getParametersAnnotations($phpcsFile, $functionPointer) as $parameterAnnotationNo => $parameterAnnotation) {
697+
if ($parameterAnnotation->getContent() === null) {
698+
continue;
699+
}
700+
697701
$parameterAnnotationParts = preg_split('~\\s+~', $parameterAnnotation->getContent(), 2);
698702
$parameterTypeHintDefinition = $parameterAnnotationParts[0];
699703
if (isset($parameterAnnotationParts[1]) && preg_match('~^(?:\.{3}\\s*)?(\$\\S+)~', $parameterAnnotationParts[1], $matches)) {

tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,10 @@ private function nullableMultidimensionalArrayParameter($a)
548548
{
549549
}
550550

551+
/**
552+
* @param
553+
* @return
554+
*/
555+
abstract public function invalidAnnotations();
556+
551557
}

0 commit comments

Comments
 (0)