Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node instanceof Closure) {
$this->processUses($node);
$hasChanged = false;

if ($node instanceof Closure && $this->processUses($node) instanceof Node) {
$hasChanged = true;
}

if ($this->processParams($node) instanceof Node) {
$hasChanged = true;
}

return $this->processParams($node);
return $hasChanged ? $node : null;
}

private function processUses(Closure $node): ?Node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private function isBetweenParentheses(Node $node): bool
*/
private function refactorAssign(array $assigns, Expression $expression): array|null
{
$hasChanged = false;

foreach ($assigns as $assign) {
if (! $assign->expr instanceof New_ && ! $assign->expr instanceof Instanceof_) {
continue;
Expand All @@ -145,6 +147,7 @@ private function refactorAssign(array $assigns, Expression $expression): array|n

// mandatory to remove parentheses
$newOrInstanceof->setAttribute(AttributeKey::ORIGINAL_NODE, null);
$hasChanged = true;

if ($isAllowed) {
continue;
Expand All @@ -164,7 +167,8 @@ private function refactorAssign(array $assigns, Expression $expression): array|n
return [new Expression($exprAssign), $expression];
}

return null;
// parentheses were removed in place, report the change so it gets printed
return $hasChanged ? [$expression] : null;
}

/**
Expand Down
Loading