mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
fixup! add DocBlockAnalyzer::addTag() method
This commit is contained in:
parent
6d143dcc69
commit
7835ec3c5d
@ -84,19 +84,6 @@ final class DocBlockAnalyzer
|
||||
return $phpDocInfo->hasTag($name);
|
||||
}
|
||||
|
||||
public function addTag(Node $node, PhpDocChildNode $phpDocChildNode): void
|
||||
{
|
||||
if ($node->getDocComment()) {
|
||||
$phpDocInfo = $this->createPhpDocInfoFromNode($node);
|
||||
$phpDocNode = $phpDocInfo->getPhpDocNode();
|
||||
} else {
|
||||
$phpDocNode = new PhpDocNode([]);
|
||||
}
|
||||
|
||||
$phpDocNode->children[] = $phpDocChildNode;
|
||||
$this->updateNodeWithPhpDocInfo($node, $phpDocInfo);
|
||||
}
|
||||
|
||||
public function removeParamTagByName(Node $node, string $name): void
|
||||
{
|
||||
if ($node->getDocComment() === null) {
|
||||
@ -109,6 +96,18 @@ final class DocBlockAnalyzer
|
||||
$this->updateNodeWithPhpDocInfo($node, $phpDocInfo);
|
||||
}
|
||||
|
||||
public function addTag(Node $node, PhpDocChildNode $phpDocChildNode): void
|
||||
{
|
||||
if ($node->getDocComment()) {
|
||||
$phpDocInfo = $this->createPhpDocInfoFromNode($node);
|
||||
$phpDocNode = $phpDocInfo->getPhpDocNode();
|
||||
$this->updateNodeWithPhpDocInfo($node, $phpDocInfo);
|
||||
} else {
|
||||
$phpDocNode = new PhpDocNode([$phpDocChildNode]);
|
||||
$node->setDocComment(new Doc($phpDocNode->__toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public function removeTagFromNode(Node $node, string $name): void
|
||||
{
|
||||
if ($node->getDocComment() === null) {
|
||||
@ -286,18 +285,6 @@ final class DocBlockAnalyzer
|
||||
return Strings::contains($name, '\\');
|
||||
}
|
||||
|
||||
private function createPhpDocInfoFromNode(Node $node): PhpDocInfo
|
||||
{
|
||||
if ($node->getDocComment() === null) {
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Node must have a comment. Check `$node->getDocComment() !== null` before passing it to %s',
|
||||
__METHOD__
|
||||
));
|
||||
}
|
||||
|
||||
return $this->phpDocInfoFactory->createFrom($node->getDocComment()->getText());
|
||||
}
|
||||
|
||||
private function updateNodeWithPhpDocInfo(Node $node, PhpDocInfo $phpDocInfo): void
|
||||
{
|
||||
// skip if has no doc comment
|
||||
@ -314,4 +301,16 @@ final class DocBlockAnalyzer
|
||||
// no comments, null
|
||||
$node->setAttribute('comments', null);
|
||||
}
|
||||
|
||||
private function createPhpDocInfoFromNode(Node $node): PhpDocInfo
|
||||
{
|
||||
if ($node->getDocComment() === null) {
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Node must have a comment. Check `$node->getDocComment() !== null` before passing it to %s',
|
||||
__METHOD__
|
||||
));
|
||||
}
|
||||
|
||||
return $this->phpDocInfoFactory->createFrom($node->getDocComment()->getText());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user