Skip to content

Commit 33c71bd

Browse files
committed
TypeHintDeclarationSniff ignores methods with @inheritdoc
1 parent 71e9940 commit 33c71bd

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ private function checkParametersTypeHints(\PHP_CodeSniffer_File $phpcsFile, int
9393
return;
9494
}
9595

96+
if ($this->hasInheritdocAnnotation($phpcsFile, $functionPointer)) {
97+
return;
98+
}
99+
96100
$parametersTypeHintsDefinitions = $this->getFunctionParameterTypeHintsDefinitions($phpcsFile, $functionPointer);
97101

98102
if (!SuppressHelper::isSniffSuppressed($phpcsFile, $functionPointer, $this->getSniffName(self::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION))) {
@@ -275,6 +279,10 @@ private function checkReturnTypeHints(\PHP_CodeSniffer_File $phpcsFile, int $fun
275279
return;
276280
}
277281

282+
if ($this->hasInheritdocAnnotation($phpcsFile, $functionPointer)) {
283+
return;
284+
}
285+
278286
$returnTypeHint = FunctionHelper::findReturnTypeHint($phpcsFile, $functionPointer);
279287
$returnAnnotation = FunctionHelper::findReturnAnnotation($phpcsFile, $functionPointer);
280288
$hasReturnAnnotation = $returnAnnotation !== null && $returnAnnotation->getContent() !== null;
@@ -475,6 +483,10 @@ private function checkUselessDocComment(\PHP_CodeSniffer_File $phpcsFile, int $f
475483
return;
476484
}
477485

486+
if ($this->hasInheritdocAnnotation($phpcsFile, $functionPointer)) {
487+
return;
488+
}
489+
478490
if (!DocCommentHelper::hasDocComment($phpcsFile, $functionPointer)) {
479491
return;
480492
}
@@ -923,4 +935,9 @@ private function getUselessParameterNames(\PHP_CodeSniffer_File $phpcsFile, int
923935
return $uselessParameterNames;
924936
}
925937

938+
private function hasInheritdocAnnotation(\PHP_CodeSniffer_File $phpcsFile, int $functionPointer): bool
939+
{
940+
return count(AnnotationHelper::getAnnotationsByName($phpcsFile, $functionPointer, '@inheritdoc')) !== 0;
941+
}
942+
926943
}

tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,4 +615,12 @@ public function returnpartialUseWithAliasTraversable(): DoctrineCollections\Arra
615615
return new DoctrineCollections\ArrayCollection();
616616
}
617617

618+
/**
619+
* @inheritdoc
620+
*/
621+
public function inheritdoc($a)
622+
{
623+
return true;
624+
}
625+
618626
}

0 commit comments

Comments
 (0)