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
Expand Up @@ -197,7 +197,7 @@ protected function traverseArray(array $nodes): array

if ($originalNodeNodeClass !== $return::class) {
// stop traversing as node type changed and visitors won't work
return $nodes;
continue 2;
Copy link
Member Author

@samsonasik samsonasik Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba this is the fix, it will continue to next nodes as node is on outer loop of collection of nodes, as different nodes not yet visited :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought return would stop everything too soon.
Looks good 👍

}
} elseif (\is_array($return)) {
$doNodes[] = [$i, $return];
Expand Down
31 changes: 31 additions & 0 deletions tests/Issues/InlineIfReplaceBlock/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Issues\InlineIfReplaceBlock\Fixture;

{
is_null($userId) && $userId = 5;

{}
}

{
is_null($userId) && $userId = 5;

{}
}

?>
-----
<?php

namespace Rector\Tests\Issues\InlineIfReplaceBlock\Fixture;

if (is_null($userId)) {
$userId = 5;
}

if (is_null($userId)) {
$userId = 5;
}

?>
28 changes: 28 additions & 0 deletions tests/Issues/InlineIfReplaceBlock/InlineIfReplaceBlockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\InlineIfReplaceBlock;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class InlineIfReplaceBlockTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
10 changes: 10 additions & 0 deletions tests/Issues/InlineIfReplaceBlock/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Block\ReplaceBlockToItsStmtsRector;

return RectorConfig::configure()
->withRules([InlineIfToExplicitIfRector::class, ReplaceBlockToItsStmtsRector::class]);