Skip to content

Commit d7f2609

Browse files
authored
[internal] Fix inline replace block removal not removed on deep block for InlineIfToExplicitIfRector + ReplaceBlockToItsStmtsRector (#7764)
* [internal] Fix inline replace block removal not removed on deep block for InlineIfToExplicitIfRector + ReplaceBlockToItsStmtsRector * Fix
1 parent 17f8d5c commit d7f2609

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function traverseArray(array $nodes): array
197197

198198
if ($originalNodeNodeClass !== $return::class) {
199199
// stop traversing as node type changed and visitors won't work
200-
return $nodes;
200+
continue 2;
201201
}
202202
} elseif (\is_array($return)) {
203203
$doNodes[] = [$i, $return];
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\Issues\InlineIfReplaceBlock\Fixture;
4+
5+
{
6+
is_null($userId) && $userId = 5;
7+
8+
{}
9+
}
10+
11+
{
12+
is_null($userId) && $userId = 5;
13+
14+
{}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Tests\Issues\InlineIfReplaceBlock\Fixture;
22+
23+
if (is_null($userId)) {
24+
$userId = 5;
25+
}
26+
27+
if (is_null($userId)) {
28+
$userId = 5;
29+
}
30+
31+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\InlineIfReplaceBlock;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class InlineIfReplaceBlockTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\DeadCode\Rector\Block\ReplaceBlockToItsStmtsRector;
8+
9+
return RectorConfig::configure()
10+
->withRules([InlineIfToExplicitIfRector::class, ReplaceBlockToItsStmtsRector::class]);

0 commit comments

Comments
 (0)