mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
drop node removing logic from DocBlockAnalyzer, make use of better-phpdoc-parser dev
This commit is contained in:
parent
f3defe7677
commit
0fd12eaee2
@ -21,7 +21,7 @@
|
||||
"symfony/dependency-injection": "^4.0",
|
||||
"symfony/finder": "^4.0",
|
||||
"symplify/better-reflection-docblock": "^4.0",
|
||||
"symplify/better-phpdoc-parser": "^4.1",
|
||||
"symplify/better-phpdoc-parser": "dev-master",
|
||||
"symplify/package-builder": "^4.1"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@ -100,10 +100,7 @@ final class DocBlockAnalyzer
|
||||
return $docBlock->hasTag($annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo move to PhpDocInfo
|
||||
*/
|
||||
public function removeAnnotationFromNode(Node $node, string $name, string $content = ''): void
|
||||
public function removeAnnotationFromNode(Node $node, string $name, ?string $content = null): void
|
||||
{
|
||||
// no doc block? skip
|
||||
if ($node->getDocComment() === null) {
|
||||
@ -112,27 +109,11 @@ final class DocBlockAnalyzer
|
||||
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFrom($node->getDocComment()->getText());
|
||||
|
||||
// add PhpDocInfoManipulator ? - add logic to the Symplify core, starting with test first
|
||||
$phpDocNode = $phpDocInfo->getPhpDocNode();
|
||||
|
||||
$tagsByName = $phpDocNode->getTagsByName('@' . $name);
|
||||
|
||||
foreach ($tagsByName as $tagByName) {
|
||||
if ($content) {
|
||||
if ($tagByName->value instanceof ParamTagValueNode) {
|
||||
if ($tagByName->value->parameterName === '$' . $content) {
|
||||
$this->removeTagFromPhpDocNode($phpDocNode, $tagByName);
|
||||
}
|
||||
} elseif ((string) $tagByName->value === $content) {
|
||||
$this->removeTagFromPhpDocNode($phpDocNode, $tagByName);
|
||||
}
|
||||
} else {
|
||||
$this->removeTagFromPhpDocNode($phpDocNode, $tagByName);
|
||||
}
|
||||
if ($content === null) {
|
||||
$phpDocInfo->removeTagByName($name);
|
||||
}
|
||||
|
||||
$docBlock = $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
|
||||
|
||||
$this->saveNewDocBlockToNode($node, $docBlock);
|
||||
}
|
||||
|
||||
@ -278,18 +259,6 @@ final class DocBlockAnalyzer
|
||||
throw new NotImplementedException(__METHOD__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo move to PhpDocInfo
|
||||
*/
|
||||
private function removeTagFromPhpDocNode(PhpDocNode $phpDocNode, PhpDocTagNode $phpDocTagNode): void
|
||||
{
|
||||
foreach ($phpDocNode->children as $key => $phpDocChildNode) {
|
||||
if ($phpDocChildNode === $phpDocTagNode) {
|
||||
unset($phpDocNode->children[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param VarTagValueNode|ParamTagValueNode|ReturnTagValueNode $phpDocTagValueNode
|
||||
*/
|
||||
|
@ -112,7 +112,7 @@ CODE_SAMPLE
|
||||
$classMethodNode->stmts = array_merge($classMethodNode->stmts, $yieldNodes);
|
||||
|
||||
// 3. remove doc block
|
||||
$this->docBlockAnalyzer->removeAnnotationFromNode($classMethodNode, 'return', '');
|
||||
$this->docBlockAnalyzer->removeAnnotationFromNode($classMethodNode, 'return');
|
||||
|
||||
return $classMethodNode;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user