diff --git a/src/AbstractFixer.php b/src/AbstractFixer.php index 2fc82286271..6ae3b8a8cd6 100644 --- a/src/AbstractFixer.php +++ b/src/AbstractFixer.php @@ -170,7 +170,7 @@ public function configure(array $configuration = null) } /** - * {@inheritdoc} + * @return FixerConfigurationResolverInterface */ public function getConfigurationDefinition() { diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index c7a35188d89..874009bd5d8 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -553,6 +553,62 @@ static function (Token $token) { ); } + /** + * @dataProvider provideSrcClassCases + * + * @param string $className + */ + public function testInheritdocIsNotAbused($className) + { + $rc = new \ReflectionClass($className); + + $allowedMethods = array_map( + function (\ReflectionClass $interface) { + return $this->getPublicMethodNames($interface); + }, + $rc->getInterfaces() + ); + + if (\count($allowedMethods)) { + $allowedMethods = array_merge(...array_values($allowedMethods)); + } + + $parentClass = $rc; + while (false !== $parentClass = $parentClass->getParentClass()) { + foreach ($parentClass->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $method) { + $allowedMethods[] = $method->getName(); + } + } + + $allowedMethods = array_unique($allowedMethods); + + $methodsWithInheritdoc = array_filter( + $rc->getMethods(), + static function (\ReflectionMethod $rm) { + return false !== $rm->getDocComment() && stripos($rm->getDocComment(), '@inheritdoc'); + } + ); + $methodsWithInheritdoc = array_map( + static function (\ReflectionMethod $rm) { + return $rm->getName(); + }, + $methodsWithInheritdoc + ); + + $extraMethods = array_diff($methodsWithInheritdoc, $allowedMethods); + + static::assertEmpty( + $extraMethods, + sprintf( + "Class '%s' should not have methods with '@inheritdoc' in PHPDoc that are not inheriting PHPDoc.\nViolations:\n%s", + $className, + implode("\n", array_map(static function ($item) { + return " * {$item}"; + }, $extraMethods)) + ) + ); + } + public function provideSrcClassCases() { return array_map(