Skip to content

Commit 4c506f6

Browse files
committed
clean flag
1 parent f585209 commit 4c506f6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,19 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
142142
$messageArgument = $new->args[0] ?? null;
143143
$shouldUseNamedArguments = $messageArgument instanceof Arg && $messageArgument->name instanceof Identifier;
144144

145+
$hasChanged = false;
145146
if (! isset($new->args[0])) {
146147
// get previous message
147148
$getMessageMethodCall = new MethodCall($caughtThrowableVariable, 'getMessage');
148149
$new->args[0] = new Arg($getMessageMethodCall);
150+
$hasChanged = true;
149151
} elseif ($new->args[0] instanceof Arg && $new->args[0]->name instanceof Identifier && $new->args[0]->name->toString() === 'previous' && $this->nodeComparator->areNodesEqual(
150152
$new->args[0]->value,
151153
$caughtThrowableVariable
152154
)) {
153155
$new->args[0]->name->name = 'message';
154156
$new->args[0]->value = new MethodCall($caughtThrowableVariable, 'getMessage');
157+
$hasChanged = true;
155158
}
156159

157160
if (! isset($new->getArgs()[1])) {
@@ -161,9 +164,10 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
161164
new MethodCall($caughtThrowableVariable, 'getCode'),
162165
name: $shouldUseNamedArguments ? new Identifier('code') : null
163166
);
167+
$hasChanged = true;
168+
} else {
169+
return null;
164170
}
165-
166-
return null;
167171
}
168172

169173
/** @var Arg $arg1 */
@@ -175,7 +179,8 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
175179
name: $shouldUseNamedArguments ? new Identifier('code') : null
176180
);
177181
$new->args[$exceptionArgumentPosition] = $arg1;
178-
} else {
182+
$hasChanged = true;
183+
} elseif (! $hasChanged) {
179184
return null;
180185
}
181186
} else {

0 commit comments

Comments
 (0)