Skip to content

Commit

Permalink
PhpStormStubsSourceStubber should remove @deprecated annotation when …
Browse files Browse the repository at this point in the history
…element is not deprecated
  • Loading branch information
kukulich committed Nov 28, 2021
1 parent e312a7b commit de66f9f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ private function addDeprecatedDocComment(Node\Stmt\ClassLike|Node\Stmt\ClassCons
}

if (! $this->isDeprecatedInPhpVersion($node)) {
$this->removeAnnotationFromDocComment($node, 'deprecated');

return;
}

Expand All @@ -536,6 +538,19 @@ private function addAnnotationToDocComment(
$node->setDocComment(new Doc($docCommentText));
}

private function removeAnnotationFromDocComment(
Node\Stmt\ClassLike|Node\Stmt\ClassConst|Node\Stmt\Property|Node\Stmt\ClassMethod|Node\Stmt\Function_|Node\Stmt\Const_ $node,
string $annotationName,
): void {
$docComment = $node->getDocComment();
if ($docComment === null) {
return;
}

$docCommentText = preg_replace('~@' . $annotationName . '.*$~m', '', $docComment->getText());
$node->setDocComment(new Doc($docCommentText));
}

private function isCoreExtension(string $extension): bool
{
return in_array($extension, self::CORE_EXTENSIONS, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,9 @@ public function dataFunctionIsDeprecatedInPhpVersion(): array
['create_function', 70100, false],
['create_function', 70199, false],
['create_function', 70200, true],
['date_sunrise', 80000, false],
['date_sunrise', 80099, false],
['date_sunrise', 80100, true],
];
}

Expand Down

0 comments on commit de66f9f

Please sign in to comment.