Merge pull request #3794 from rectorphp/removal-bracket

fix removing of doc
This commit is contained in:
kodiakhq[bot] 2020-07-26 17:34:00 +00:00 committed by GitHub
commit 0f361a5a82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 30 deletions

View File

@ -429,8 +429,6 @@ final class BetterStandardPrinter extends Standard
continue;
}
$this->makeSureCommentWasNotAddedOnWrongPlace($node);
$this->docBlockManipulator->updateNodeWithPhpDocInfo($node);
}
}
@ -453,30 +451,4 @@ final class BetterStandardPrinter extends Standard
{
return $wrap . $string->value . $wrap;
}
private function makeSureCommentWasNotAddedOnWrongPlace(Node $node): void
{
if (! $node instanceof Expression) {
return;
}
if ($node->getComments() === $node->expr->getComments()) {
return;
}
$commentsString = '';
foreach ($node->expr->getComments() as $comment) {
$commentsString .= $comment->getText() . PHP_EOL;
}
// docblocks are handled somewhere else
if (Strings::startsWith($commentsString, '/*')) {
return;
}
$mergedComments = array_merge($node->expr->getComments(), $node->getComments());
$mergedComments = array_unique($mergedComments);
$node->setAttribute(AttributeKey::COMMENTS, $mergedComments);
}
}

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\HttpKernel\RectorKernel;
use Rector\Core\PhpParser\Builder\MethodBuilder;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
@ -32,10 +33,13 @@ final class BetterStandardPrinterTest extends AbstractKernelTestCase
public function testAddingCommentOnSomeNodesFail(): void
{
$methodCall = new MethodCall(new Variable('this'), 'run');
$methodCall->setAttribute(AttributeKey::COMMENTS, [new Comment('// todo: fix')]);
// cannot be on MethodCall, must be Expression
$methodCallExpression = new Expression($methodCall);
$methodCallExpression->setAttribute(AttributeKey::COMMENTS, [new Comment('// todo: fix')]);
$methodBuilder = new MethodBuilder('run');
$methodBuilder->addStmt($methodCall);
$methodBuilder->addStmt($methodCallExpression);
$classMethod = $methodBuilder->getNode();