Skip to content

Commit 1e523a6

Browse files
committed
Fix
1 parent 408b839 commit 1e523a6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

rules-tests/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector/Fixture/multiple_coalesce.php.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class MultipleCoalesce
2020
{
2121
public function run($content)
2222
{
23-
if (($contentId = $content->getInternalId() ?? $content->getId()) === null) {
23+
$contentId = $content->getInternalId() ?? $content->getId();
24+
if ($contentId === null) {
2425
throw new \LogicException('content id is required for ackVersion');
2526
}
2627
}

rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private function refactorCoalesce(Coalesce $coalesce, ?Assign $assign): If_|null
202202
/**
203203
* @return If_|Stmt[]|null
204204
*/
205-
private function processCoalesce(Coalesce $coalesce, ?Assign $assign, bool $innerAssign = false): If_|null|array
205+
private function processCoalesce(Coalesce $coalesce, ?Assign $assign, bool $assignEarly = false): If_|null|array
206206
{
207207
if (! $this->coalesceAnalyzer->hasIssetableLeft($coalesce)) {
208208
return null;
@@ -219,9 +219,11 @@ private function processCoalesce(Coalesce $coalesce, ?Assign $assign, bool $inne
219219

220220
$assign->expr = $coalesce->left;
221221

222-
if ($innerAssign && $if->cond instanceof Identical) {
223-
$if->cond->left = new Assign($assign->var, $if->cond->left);
224-
return $if;
222+
if ($assignEarly && $if->cond instanceof Identical) {
223+
$expression = new Expression(new Assign($assign->var, $if->cond->left));
224+
$if->cond->left = $assign->var;
225+
226+
return [$expression, $if];
225227
}
226228

227229
return [$if, new Expression($assign)];

0 commit comments

Comments
 (0)