Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
{
}

}