Skip to content

Commit 408b839

Browse files
committed
direct assign
1 parent 4b40665 commit 408b839

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ class MultipleCoalesce
2020
{
2121
public function run($content)
2222
{
23-
if (($content->getInternalId() ?? $content->getId()) === null) {
23+
if (($contentId = $content->getInternalId() ?? $content->getId()) === null) {
2424
throw new \LogicException('content id is required for ackVersion');
2525
}
26-
$contentId = $content->getInternalId() ?? $content->getId();
2726
}
2827
}
2928

rules/DowngradePhp80/Rector/Expression/DowngradeThrowExprRector.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private function refactorCoalesce(Coalesce $coalesce, ?Assign $assign): If_|null
190190

191191
if ($rightCoalesce instanceof Throw_) {
192192
$coalesce = new Coalesce($leftCoalesce, $rightCoalesce);
193-
return $this->processCoalesce($coalesce, $assign);
193+
return $this->processCoalesce($coalesce, $assign, true);
194194
}
195195

196196
return null;
@@ -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): If_|null|array
205+
private function processCoalesce(Coalesce $coalesce, ?Assign $assign, bool $innerAssign = false): If_|null|array
206206
{
207207
if (! $this->coalesceAnalyzer->hasIssetableLeft($coalesce)) {
208208
return null;
@@ -219,6 +219,11 @@ private function processCoalesce(Coalesce $coalesce, ?Assign $assign): If_|null|
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;
225+
}
226+
222227
return [$if, new Expression($assign)];
223228
}
224229

0 commit comments

Comments
 (0)