Skip to content

Commit 6b89297

Browse files
committed
Different @throws inheritDoc merging
1 parent a772544 commit 6b89297

2 files changed

Lines changed: 9 additions & 23 deletions

File tree

src/PhpDoc/ResolvedPhpDocBlock.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
1414
use PHPStan\Type\Generic\TemplateTypeHelper;
1515
use PHPStan\Type\Generic\TemplateTypeMap;
16-
use PHPStan\Type\TypeCombinator;
1716

1817
class ResolvedPhpDocBlock
1918
{
@@ -540,32 +539,19 @@ private static function mergeOneParentReturnTag(?ReturnTag $returnTag, self $par
540539
*/
541540
private static function mergeThrowsTags(?ThrowsTag $throwsTag, array $parents): ?ThrowsTag
542541
{
542+
if ($throwsTag !== null) {
543+
return $throwsTag;
544+
}
543545
foreach ($parents as $parent) {
544-
$result = self::mergeOneParentThrowsTag($throwsTag, $parent);
546+
$result = $parent->getThrowsTag();
545547
if ($result === null) {
546548
continue;
547549
}
548550

549-
$throwsTag = $result;
550-
}
551-
552-
return $throwsTag;
553-
}
554-
555-
private static function mergeOneParentThrowsTag(?ThrowsTag $throwsTag, self $parent): ?ThrowsTag
556-
{
557-
$parentThrowsTag = $parent->getThrowsTag();
558-
if ($parentThrowsTag === null) {
559-
return $throwsTag;
560-
}
561-
562-
if ($throwsTag === null) {
563-
return $parentThrowsTag;
551+
return $result;
564552
}
565553

566-
return new ThrowsTag(
567-
TypeCombinator::union($throwsTag->getType(), $parentThrowsTag->getType())
568-
);
554+
return null;
569555
}
570556

571557
/**

tests/PHPStan/Rules/PhpDoc/InvalidThrowsPhpDocValueRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public function testMergeInheritedPhpDocs(): void
5959
19,
6060
],
6161
[
62-
'PHPDoc tag @throws with type InvalidThrowsPhpDocMergeInherited\A|InvalidThrowsPhpDocMergeInherited\B|InvalidThrowsPhpDocMergeInherited\C|InvalidThrowsPhpDocMergeInherited\D is not subtype of Throwable',
62+
'PHPDoc tag @throws with type InvalidThrowsPhpDocMergeInherited\C|InvalidThrowsPhpDocMergeInherited\D is not subtype of Throwable',
6363
28,
6464
],
6565
[
66-
'PHPDoc tag @throws with type InvalidThrowsPhpDocMergeInherited\A|InvalidThrowsPhpDocMergeInherited\B|InvalidThrowsPhpDocMergeInherited\C|InvalidThrowsPhpDocMergeInherited\D is not subtype of Throwable',
66+
'PHPDoc tag @throws with type InvalidThrowsPhpDocMergeInherited\C|InvalidThrowsPhpDocMergeInherited\D is not subtype of Throwable',
6767
34,
6868
],
6969
[
70-
'PHPDoc tag @throws with type InvalidThrowsPhpDocMergeInherited\A|InvalidThrowsPhpDocMergeInherited\B|InvalidThrowsPhpDocMergeInherited\C|InvalidThrowsPhpDocMergeInherited\D is not subtype of Throwable',
70+
'PHPDoc tag @throws with type InvalidThrowsPhpDocMergeInherited\C|InvalidThrowsPhpDocMergeInherited\D is not subtype of Throwable',
7171
39,
7272
],
7373
]);

0 commit comments

Comments
 (0)