Skip to content

Commit

Permalink
Updated Rector to commit 8b983280a817e815b0de72e02d2fe99d201c5a1c
Browse files Browse the repository at this point in the history
rectorphp/rector-src@8b98328  [Php80] Skip used in compact() on RemoveUnusedVariableInCatchRector  (#6152)
  • Loading branch information
TomasVotruba committed Jul 15, 2024
1 parent 427f73f commit a86c4a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\TryCatch;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
use Rector\NodeManipulator\StmtsManipulator;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractRector;
Expand All @@ -29,10 +30,16 @@ final class RemoveUnusedVariableInCatchRector extends AbstractRector implements
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
public function __construct(StmtsManipulator $stmtsManipulator, BetterNodeFinder $betterNodeFinder)
/**
* @readonly
* @var \Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer
*/
private $exprUsedInNodeAnalyzer;
public function __construct(StmtsManipulator $stmtsManipulator, BetterNodeFinder $betterNodeFinder, ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer)
{
$this->stmtsManipulator = $stmtsManipulator;
$this->betterNodeFinder = $betterNodeFinder;
$this->exprUsedInNodeAnalyzer = $exprUsedInNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -87,8 +94,10 @@ public function refactor(Node $node) : ?Node
}
/** @var string $variableName */
$variableName = $this->getName($caughtVar);
$isVariableUsed = (bool) $this->betterNodeFinder->findVariableOfName($catch->stmts, $variableName);
if ($isVariableUsed) {
$isFoundInCatchStmts = (bool) $this->betterNodeFinder->findFirst($catch->stmts, function (Node $subNode) use($caughtVar) : bool {
return $this->exprUsedInNodeAnalyzer->isUsed($subNode, $caughtVar);
});
if ($isFoundInCatchStmts) {
continue;
}
if ($this->stmtsManipulator->isVariableUsedInNextStmt($node, $key + 1, $variableName)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '36b475d84ae192f498854c796bd8246038a5bc7a';
public const PACKAGE_VERSION = '8b983280a817e815b0de72e02d2fe99d201c5a1c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-07-15 23:58:42';
public const RELEASE_DATE = '2024-07-16 05:56:46';
/**
* @var int
*/
Expand Down

0 comments on commit a86c4a9

Please sign in to comment.