Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\Php74\Rector\If_\IfToNullCoalescingAssignRector\Fixture;

/**
* Fallback value description
*
* @var int $limit
*/
if (! isset($limit)) {
$limit = 100;
}

// simple comment
if (! isset($name)) {
$name = 'default';
}

?>
-----
<?php

namespace Rector\Tests\Php74\Rector\If_\IfToNullCoalescingAssignRector\Fixture;

/**
* Fallback value description
*
* @var int $limit
*/
$limit ??= 100;

// simple comment
$name ??= 'default';

?>
5 changes: 4 additions & 1 deletion rules/Php74/Rector/If_/IfToNullCoalescingAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public function refactor(Node $node): ?Expression
return null;
}

return new Expression(new AssignCoalesce($assign->var, $assign->expr));
$expression = new Expression(new AssignCoalesce($assign->var, $assign->expr));
$this->mirrorComments($expression, $node);

return $expression;
}

public function provideMinPhpVersion(): int
Expand Down