Skip to content

Commit

Permalink
Resolve deprecated tag also from parents
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Nov 21, 2021
1 parent c00ba35 commit a8322b2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/PhpDoc/ResolvedPhpDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\PhpDoc;

use PHPStan\Analyser\NameScope;
use PHPStan\PhpDoc\Tag\DeprecatedTag;
use PHPStan\PhpDoc\Tag\MixinTag;
use PHPStan\PhpDoc\Tag\ParamTag;
use PHPStan\PhpDoc\Tag\ReturnTag;
Expand Down Expand Up @@ -189,7 +190,7 @@ public function merge(array $parents, array $parentPhpDocBlocks): self
$result->mixinTags = $this->getMixinTags();
$result->typeAliasTags = $this->getTypeAliasTags();
$result->typeAliasImportTags = $this->getTypeAliasImportTags();
$result->deprecatedTag = $this->getDeprecatedTag();
$result->deprecatedTag = self::mergeDeprecatedTags($this->getDeprecatedTag(), $parents);
$result->isDeprecated = $result->deprecatedTag !== null;
$result->isInternal = $this->isInternal();
$result->isFinal = $this->isFinal();
Expand Down Expand Up @@ -633,6 +634,25 @@ private static function mergeOneParentReturnTag(?ReturnTag $returnTag, self $par
return self::resolveTemplateTypeInTag($parentReturnTag->toImplicit(), $phpDocBlock);
}

/**
* @param array<int, self> $parents
*/
private static function mergeDeprecatedTags(?DeprecatedTag $deprecatedTag, array $parents): ?DeprecatedTag
{
if ($deprecatedTag !== null) {
return $deprecatedTag;
}
foreach ($parents as $parent) {
$result = $parent->getDeprecatedTag();
if ($result === null) {
continue;
}
return $result;
}

return null;
}

/**
* @param array<int, self> $parents
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,11 @@ public function testNonDeprecatedNativeFunctions(): void
$this->assertFalse($reflectionProvider->getFunction(new Name('function_exists'), null)->isDeprecated()->yes());
}

public function testDeprecatedMethodsFromInterface(): void
{
$reflectionProvider = $this->createReflectionProvider();
$class = $reflectionProvider->getClass(\DeprecatedAnnotations\DeprecatedBar::class);
$this->assertTrue($class->getNativeMethod('superDeprecated')->isDeprecated()->yes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,31 @@ public function deprecatedFoo() {
}

}

/**
* @deprecated This is totally deprecated.
*/
interface BarInterface
{

/**
* @deprecated This is totally deprecated.
*/
public function superDeprecated();

}

/**
* {@inheritdoc}
*/
class DeprecatedBar implements BarInterface
{

/**
* {@inheritdoc}
*/
public function superDeprecated()
{
}

}

0 comments on commit a8322b2

Please sign in to comment.