Skip to content

Commit

Permalink
[Php55] Handle crash after exit() on GetCalledClassToSelfClassRector (#…
Browse files Browse the repository at this point in the history
…5372)

* [Php55] Handle crash after exit() on GetCalledClassToSelfClassRector

* fixed 🎉

* add test after die
  • Loading branch information
samsonasik committed Dec 18, 2023
1 parent affdec9 commit 02a30d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

die('blocked');

function my_function () {
// It seems like this call below can be any function,
// so long as it returns something
return implode(',', []);
}

echo my_function();
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

exit('blocked');

function my_function () {
// It seems like this call below can be any function,
// so long as it returns something
return implode(',', []);
}

echo my_function();
9 changes: 8 additions & 1 deletion src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Rector\Core\PHPStan\NodeVisitor;

use PhpParser\Node;
use PhpParser\Node\Expr\Exit_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeVisitorAbstract;
use PHPStan\Analyser\MutatingScope;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
Expand Down Expand Up @@ -41,7 +43,12 @@ public function enterNode(Node $node): ?Node
);

foreach ($node->stmts as $stmt) {
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
if ($stmt instanceof Expression && $stmt->expr instanceof Exit_) {
$isPassedUnreachableStmt = true;
continue;
}

if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
$isPassedUnreachableStmt = true;
continue;
}
Expand Down

0 comments on commit 02a30d4

Please sign in to comment.