Skip to content

Commit

Permalink
[Renaming] Handle crash on RenameFunctionRector with die() and $_SESS…
Browse files Browse the repository at this point in the history
…ION part 2 (#5647)

* [Renaming] Handle crash on RenameFunctionRector with die() and $_SESSION part 2

* fix
  • Loading branch information
samsonasik committed Feb 21, 2024
1 parent 00876da commit 3b44873
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
@@ -0,0 +1,55 @@
<?php

if ($_SESSION['order_in_progress'] != 1) {

$isNewUIEnabled = true;

if ($isNewUIEnabled) {
header('Location: /storefront/checkout/success');
return;
}
} else {
die('Sorry, ');
}

function insertorder() {
if (!empty($orderTaxDetails)) {

abc($orderTaxQuery);
if (abc2()) {
return false;
}
}
}

echo $_SESSION['facebook_app_id'];

?>
-----
<?php

if ($_SESSION['order_in_progress'] != 1) {

$isNewUIEnabled = true;

if ($isNewUIEnabled) {
header('Location: /storefront/checkout/success');
return;
}
} else {
die('Sorry, ');
}

function insertorder() {
if (!empty($orderTaxDetails)) {

abc($orderTaxQuery);
if (abc()) {
return false;
}
}
}

echo $_SESSION['facebook_app_id'];

?>
19 changes: 2 additions & 17 deletions src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php
Expand Up @@ -5,11 +5,8 @@
namespace Rector\PHPStan\NodeVisitor;

use PhpParser\Node;
use PhpParser\Node\Expr;
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 PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -41,11 +38,8 @@ public function enterNode(Node $node): ?Node
$mutatingScope = $this->resolveScope($node->getAttribute(AttributeKey::SCOPE));

foreach ($node->stmts as $stmt) {
if ($stmt instanceof Expression && $stmt->expr instanceof Exit_) {
$isPassedUnreachableStmt = true;
$this->processExitScope($stmt->expr, $stmt, $mutatingScope);

continue;
if (! $stmt->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) {
$this->phpStanNodeScopeResolver->processNodes([$stmt], $this->filePath, $mutatingScope);
}

if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
Expand All @@ -56,21 +50,12 @@ public function enterNode(Node $node): ?Node
if ($isPassedUnreachableStmt) {
$stmt->setAttribute(AttributeKey::IS_UNREACHABLE, true);
$stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$this->phpStanNodeScopeResolver->processNodes([$stmt], $this->filePath, $mutatingScope);
}
}

return null;
}

private function processExitScope(Exit_ $exit, Expression $expression, MutatingScope $mutatingScope): void
{
if ($exit->expr instanceof Expr && ! $exit->expr->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) {
$expression->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$this->phpStanNodeScopeResolver->processNodes([$expression], $this->filePath, $mutatingScope);
}
}

private function resolveScope(?Scope $mutatingScope): MutatingScope
{
return $mutatingScope instanceof MutatingScope ? $mutatingScope : $this->scopeFactory->createFromFile(
Expand Down

0 comments on commit 3b44873

Please sign in to comment.