Skip to content

Commit

Permalink
Merge branch '2.18'
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/AutoReview/ProjectCodeTest.php
  • Loading branch information
keradus committed Apr 30, 2021
2 parents 351fc9c + 4961df4 commit 3d7e47c
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 @@ -170,7 +170,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 @@ -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(
Expand Down

0 comments on commit 3d7e47c

Please sign in to comment.