mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +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/dependency-injection": "^4.0",
|
||||||
"symfony/finder": "^4.0",
|
"symfony/finder": "^4.0",
|
||||||
"symplify/better-reflection-docblock": "^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"
|
"symplify/package-builder": "^4.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
@ -100,10 +100,7 @@ final class DocBlockAnalyzer
|
|||||||
return $docBlock->hasTag($annotation);
|
return $docBlock->hasTag($annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function removeAnnotationFromNode(Node $node, string $name, ?string $content = null): void
|
||||||
* @todo move to PhpDocInfo
|
|
||||||
*/
|
|
||||||
public function removeAnnotationFromNode(Node $node, string $name, string $content = ''): void
|
|
||||||
{
|
{
|
||||||
// no doc block? skip
|
// no doc block? skip
|
||||||
if ($node->getDocComment() === null) {
|
if ($node->getDocComment() === null) {
|
||||||
@ -112,27 +109,11 @@ final class DocBlockAnalyzer
|
|||||||
|
|
||||||
$phpDocInfo = $this->phpDocInfoFactory->createFrom($node->getDocComment()->getText());
|
$phpDocInfo = $this->phpDocInfoFactory->createFrom($node->getDocComment()->getText());
|
||||||
|
|
||||||
// add PhpDocInfoManipulator ? - add logic to the Symplify core, starting with test first
|
if ($content === null) {
|
||||||
$phpDocNode = $phpDocInfo->getPhpDocNode();
|
$phpDocInfo->removeTagByName($name);
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$docBlock = $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
|
$docBlock = $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
|
||||||
|
|
||||||
$this->saveNewDocBlockToNode($node, $docBlock);
|
$this->saveNewDocBlockToNode($node, $docBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,18 +259,6 @@ final class DocBlockAnalyzer
|
|||||||
throw new NotImplementedException(__METHOD__);
|
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
|
* @param VarTagValueNode|ParamTagValueNode|ReturnTagValueNode $phpDocTagValueNode
|
||||||
*/
|
*/
|
||||||
|
@ -112,7 +112,7 @@ CODE_SAMPLE
|
|||||||
$classMethodNode->stmts = array_merge($classMethodNode->stmts, $yieldNodes);
|
$classMethodNode->stmts = array_merge($classMethodNode->stmts, $yieldNodes);
|
||||||
|
|
||||||
// 3. remove doc block
|
// 3. remove doc block
|
||||||
$this->docBlockAnalyzer->removeAnnotationFromNode($classMethodNode, 'return', '');
|
$this->docBlockAnalyzer->removeAnnotationFromNode($classMethodNode, 'return');
|
||||||
|
|
||||||
return $classMethodNode;
|
return $classMethodNode;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user