Skip to content

Commit a8322b2

Browse files
committed
Resolve deprecated tag also from parents
1 parent c00ba35 commit a8322b2

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/PhpDoc/ResolvedPhpDocBlock.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\PhpDoc;
44

55
use PHPStan\Analyser\NameScope;
6+
use PHPStan\PhpDoc\Tag\DeprecatedTag;
67
use PHPStan\PhpDoc\Tag\MixinTag;
78
use PHPStan\PhpDoc\Tag\ParamTag;
89
use PHPStan\PhpDoc\Tag\ReturnTag;
@@ -189,7 +190,7 @@ public function merge(array $parents, array $parentPhpDocBlocks): self
189190
$result->mixinTags = $this->getMixinTags();
190191
$result->typeAliasTags = $this->getTypeAliasTags();
191192
$result->typeAliasImportTags = $this->getTypeAliasImportTags();
192-
$result->deprecatedTag = $this->getDeprecatedTag();
193+
$result->deprecatedTag = self::mergeDeprecatedTags($this->getDeprecatedTag(), $parents);
193194
$result->isDeprecated = $result->deprecatedTag !== null;
194195
$result->isInternal = $this->isInternal();
195196
$result->isFinal = $this->isFinal();
@@ -633,6 +634,25 @@ private static function mergeOneParentReturnTag(?ReturnTag $returnTag, self $par
633634
return self::resolveTemplateTypeInTag($parentReturnTag->toImplicit(), $phpDocBlock);
634635
}
635636

637+
/**
638+
* @param array<int, self> $parents
639+
*/
640+
private static function mergeDeprecatedTags(?DeprecatedTag $deprecatedTag, array $parents): ?DeprecatedTag
641+
{
642+
if ($deprecatedTag !== null) {
643+
return $deprecatedTag;
644+
}
645+
foreach ($parents as $parent) {
646+
$result = $parent->getDeprecatedTag();
647+
if ($result === null) {
648+
continue;
649+
}
650+
return $result;
651+
}
652+
653+
return null;
654+
}
655+
636656
/**
637657
* @param array<int, self> $parents
638658
*/

tests/PHPStan/Reflection/Annotations/DeprecatedAnnotationsTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,11 @@ public function testNonDeprecatedNativeFunctions(): void
131131
$this->assertFalse($reflectionProvider->getFunction(new Name('function_exists'), null)->isDeprecated()->yes());
132132
}
133133

134+
public function testDeprecatedMethodsFromInterface(): void
135+
{
136+
$reflectionProvider = $this->createReflectionProvider();
137+
$class = $reflectionProvider->getClass(\DeprecatedAnnotations\DeprecatedBar::class);
138+
$this->assertTrue($class->getNativeMethod('superDeprecated')->isDeprecated()->yes());
139+
}
140+
134141
}

tests/PHPStan/Reflection/Annotations/data/annotations-deprecated.php

+28
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,31 @@ public function deprecatedFoo() {
187187
}
188188

189189
}
190+
191+
/**
192+
* @deprecated This is totally deprecated.
193+
*/
194+
interface BarInterface
195+
{
196+
197+
/**
198+
* @deprecated This is totally deprecated.
199+
*/
200+
public function superDeprecated();
201+
202+
}
203+
204+
/**
205+
* {@inheritdoc}
206+
*/
207+
class DeprecatedBar implements BarInterface
208+
{
209+
210+
/**
211+
* {@inheritdoc}
212+
*/
213+
public function superDeprecated()
214+
{
215+
}
216+
217+
}

0 commit comments

Comments
 (0)