Skip to content

Commit 00da8f3

Browse files
authored
[Test] Add test for crash after reprint Stmt (#6924)
1 parent 9f3665a commit 00da8f3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\ChangeSwitchTernary\Source;
6+
7+
use PhpParser\Node;
8+
use PhpParser\Node\Stmt\Expression;
9+
use Rector\PHPStan\ScopeFetcher;
10+
use Rector\Rector\AbstractRector;
11+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
12+
13+
final class AnotherExpressionRector extends AbstractRector
14+
{
15+
public function getRuleDefinition(): RuleDefinition
16+
{
17+
return new RuleDefinition('', []);
18+
}
19+
20+
public function getNodeTypes(): array
21+
{
22+
return [Expression::class];
23+
}
24+
25+
public function refactor(Node $node): ?Node
26+
{
27+
// fetch for testing crash no scope after reprint
28+
ScopeFetcher::fetch($node);
29+
30+
return null;
31+
}
32+
}

tests/Issues/ChangeSwitchTernary/config/configured_rule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector;
66
use Rector\Config\RectorConfig;
77
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
8+
use Rector\Tests\Issues\ChangeSwitchTernary\Source\AnotherExpressionRector;
89

910
return RectorConfig::configure()
10-
->withRules([ChangeSwitchToMatchRector::class, TernaryFalseExpressionToIfRector::class]);
11+
->withRules([ChangeSwitchToMatchRector::class, TernaryFalseExpressionToIfRector::class, AnotherExpressionRector::class]);

0 commit comments

Comments
 (0)