Skip to content

Commit d9dd6bf

Browse files
committed
Remove more specific PHPDoc @return from PHP 8.1 stubs
1 parent 6407aa5 commit d9dd6bf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: extractor/extract.php

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use PhpParser\Comment;
55
use PhpParser\Node;
66
use PhpParser\ParserFactory;
7+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
78
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
89
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
910
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
@@ -475,6 +476,26 @@ private function compareFunctions(Node\FunctionLike $old, Node\FunctionLike $new
475476
}
476477
}
477478

479+
if (
480+
$old->getReturnType() !== null
481+
&& $new->getReturnType() !== null
482+
&& $new->getDocComment() !== null
483+
) {
484+
if ($old->getDocComment() === null || $this->findPhpDocReturn($this->parseDocComment($old->getDocComment()->getText())) === null) {
485+
$newPhpDocNode = $this->parseDocComment($new->getDocComment()->getText());
486+
if ($this->findPhpDocReturn($newPhpDocNode) !== null) {
487+
$newPhpDocNodeWithoutReturn = new PhpDocNode(array_values(array_filter($newPhpDocNode->children, function (PhpDocChildNode $child): bool {
488+
if (!$child instanceof PhpDocTagNode) {
489+
return true;
490+
}
491+
492+
return !$child->value instanceof ReturnTagValueNode;
493+
})));
494+
$new->setDocComment(new Comment\Doc((string) $newPhpDocNodeWithoutReturn));
495+
}
496+
}
497+
}
498+
478499
return [$new];
479500
}
480501

0 commit comments

Comments
 (0)