Skip to content

Commit

Permalink
minor #5663 DX: do not abuse "inheritdoc" tag (kubawerlos)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

DX: do not abuse "inheritdoc" tag

Commits
-------

7da60a0 DX: do not abuse "inheritdoc" tag
  • Loading branch information
keradus committed Apr 30, 2021
2 parents f2e555a + 7da60a0 commit 4961df4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AbstractFixer.php
Expand Up @@ -176,7 +176,7 @@ public function configure(array $configuration = null)
}

/**
* {@inheritdoc}
* @return FixerConfigurationResolverInterface
*/
public function getConfigurationDefinition()
{
Expand Down
56 changes: 56 additions & 0 deletions tests/AutoReview/ProjectCodeTest.php
Expand Up @@ -522,6 +522,62 @@ public function testAllCodeContainSingleClassy($className)
}
}

/**
* @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(
Expand Down

0 comments on commit 4961df4

Please sign in to comment.