drop node removing logic from DocBlockAnalyzer, make use of better-phpdoc-parser dev

This commit is contained in:
Tomas Votruba 2018-04-30 10:57:22 +02:00
parent f3defe7677
commit 0fd12eaee2
3 changed files with 5 additions and 36 deletions

View File

@ -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": {

View File

@ -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
*/ */

View File

@ -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;
} }