Skip to content

Commit e699e2f

Browse files
committed
fix flag has changed
1 parent 4c9bd83 commit e699e2f

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,30 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
165165
name: $shouldUseNamedArguments ? new Identifier('code') : null
166166
);
167167
$hasChanged = true;
168-
} else {
168+
} elseif (! $hasChanged) {
169169
return null;
170170
}
171-
}
172-
173-
/** @var Arg $arg1 */
174-
$arg1 = $new->args[1];
175-
if ($arg1->name instanceof Identifier && $arg1->name->toString() === 'previous') {
176-
if ($this->hasCodeParameter($new->class)) {
177-
$new->args[1] = new Arg(
178-
new MethodCall($caughtThrowableVariable, 'getCode'),
179-
name: $shouldUseNamedArguments ? new Identifier('code') : null
171+
} else {
172+
/** @var Arg $arg1 */
173+
$arg1 = $new->args[1];
174+
if ($arg1->name instanceof Identifier && $arg1->name->toString() === 'previous') {
175+
if ($this->hasCodeParameter($new->class)) {
176+
$new->args[1] = new Arg(
177+
new MethodCall($caughtThrowableVariable, 'getCode'),
178+
name: $shouldUseNamedArguments ? new Identifier('code') : null
179+
);
180+
$new->args[$exceptionArgumentPosition] = $arg1;
181+
$hasChanged = true;
182+
} elseif (! $hasChanged) {
183+
return null;
184+
}
185+
} else {
186+
$new->args[$exceptionArgumentPosition] = new Arg(
187+
$caughtThrowableVariable,
188+
name: $shouldUseNamedArguments ? new Identifier('previous') : null
180189
);
181-
$new->args[$exceptionArgumentPosition] = $arg1;
182190
$hasChanged = true;
183-
} elseif (! $hasChanged) {
184-
return null;
185191
}
186-
} else {
187-
$new->args[$exceptionArgumentPosition] = new Arg(
188-
$caughtThrowableVariable,
189-
name: $shouldUseNamedArguments ? new Identifier('previous') : null
190-
);
191-
$hasChanged = true;
192192
}
193193

194194
if (! $hasChanged) {

0 commit comments

Comments
 (0)