Skip to content

Commit 02a30d4

Browse files
authored
[Php55] Handle crash after exit() on GetCalledClassToSelfClassRector (#5372)
* [Php55] Handle crash after exit() on GetCalledClassToSelfClassRector * fixed 🎉 * add test after die
1 parent affdec9 commit 02a30d4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
die('blocked');
4+
5+
function my_function () {
6+
// It seems like this call below can be any function,
7+
// so long as it returns something
8+
return implode(',', []);
9+
}
10+
11+
echo my_function();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
exit('blocked');
4+
5+
function my_function () {
6+
// It seems like this call below can be any function,
7+
// so long as it returns something
8+
return implode(',', []);
9+
}
10+
11+
echo my_function();

src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace Rector\Core\PHPStan\NodeVisitor;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\Expr\Exit_;
89
use PhpParser\Node\Stmt\ClassLike;
910
use PhpParser\Node\Stmt\Declare_;
11+
use PhpParser\Node\Stmt\Expression;
1012
use PhpParser\NodeVisitorAbstract;
1113
use PHPStan\Analyser\MutatingScope;
1214
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
@@ -41,7 +43,12 @@ public function enterNode(Node $node): ?Node
4143
);
4244

4345
foreach ($node->stmts as $stmt) {
44-
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
46+
if ($stmt instanceof Expression && $stmt->expr instanceof Exit_) {
47+
$isPassedUnreachableStmt = true;
48+
continue;
49+
}
50+
51+
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
4552
$isPassedUnreachableStmt = true;
4653
continue;
4754
}

0 commit comments

Comments
 (0)