Skip to content

Commit 05c5b7f

Browse files
authored
Return node when node mutated in place, so change is recorded (#418)
1 parent e376b91 commit 05c5b7f

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ public function getNodeTypes(): array
8686
*/
8787
public function refactor(Node $node): ?Node
8888
{
89-
if ($node instanceof Closure) {
90-
$this->processUses($node);
89+
$hasChanged = false;
90+
91+
if ($node instanceof Closure && $this->processUses($node) instanceof Node) {
92+
$hasChanged = true;
93+
}
94+
95+
if ($this->processParams($node) instanceof Node) {
96+
$hasChanged = true;
9197
}
9298

93-
return $this->processParams($node);
99+
return $hasChanged ? $node : null;
94100
}
95101

96102
private function processUses(Closure $node): ?Node

‎rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ private function isBetweenParentheses(Node $node): bool
128128
*/
129129
private function refactorAssign(array $assigns, Expression $expression): array|null
130130
{
131+
$hasChanged = false;
132+
131133
foreach ($assigns as $assign) {
132134
if (! $assign->expr instanceof New_ && ! $assign->expr instanceof Instanceof_) {
133135
continue;
@@ -145,6 +147,7 @@ private function refactorAssign(array $assigns, Expression $expression): array|n
145147

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

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

167-
return null;
170+
// parentheses were removed in place, report the change so it gets printed
171+
return $hasChanged ? [$expression] : null;
168172
}
169173

170174
/**

0 commit comments

Comments
 (0)