You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to write a rule which copies the body in a function into a method. I know this is not the most usual use case here but I am trying because Drupal uses Drupal Rector and I'd rather integrate with that than ship an entirely separate utility.
So I have:
public function getNodeTypes(): array
{
return [\PhpParser\Node\Stmt\Function_::class];
}
public function refactor(Node $node): ?Node
{
$prettyPrinter = new BetterStandardPrinter();
echo $prettyPrinter->printFormatPreserving($node->getStmts(), $node->getStmts(), $this->file->getOldTokens());
return $node;
}
While echo $prettyPrinter->print($node) prints the function body, printFormatPreserving called like this prints the entire file instead of just the function body. Please advise.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to write a rule which copies the body in a function into a method. I know this is not the most usual use case here but I am trying because Drupal uses Drupal Rector and I'd rather integrate with that than ship an entirely separate utility.
So I have:
While
echo $prettyPrinter->print($node)
prints the function body,printFormatPreserving
called like this prints the entire file instead of just the function body. Please advise.Beta Was this translation helpful? Give feedback.
All reactions