mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Merge pull request #3794 from rectorphp/removal-bracket
fix removing of doc
This commit is contained in:
commit
0f361a5a82
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user