mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-15 15:42:22 +00:00
Updated Rector to commit 7ec1be6b828042b27e3f40ed41b3285a6fe78502
7ec1be6b82
[DeadCode]: Support functions in RemoveUnusedVariableAssignRector (#5249)
This commit is contained in:
parent
374bab157a
commit
9aef117ab1
|
@ -81,15 +81,16 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
return [ClassMethod::class, Stmt\Function_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
* @param ClassMethod|Stmt\Function_ $node
|
||||
* @return null|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?ClassMethod
|
||||
public function refactorWithScope(Node $node, Scope $scope)
|
||||
{
|
||||
$classMethodStmts = $node->stmts;
|
||||
if ($classMethodStmts === null) {
|
||||
$stmts = $node->stmts;
|
||||
if ($stmts === null || $stmts === []) {
|
||||
return null;
|
||||
}
|
||||
// we cannot be sure here
|
||||
|
@ -99,14 +100,14 @@ CODE_SAMPLE
|
|||
if ($this->containsFileIncludes($node)) {
|
||||
return null;
|
||||
}
|
||||
$assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($classMethodStmts);
|
||||
$assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($stmts);
|
||||
$hasChanged = \false;
|
||||
foreach ($assignedVariableNamesByStmtPosition as $stmtPosition => $variableName) {
|
||||
if ($this->isVariableUsedInFollowingStmts($node, $stmtPosition, $variableName)) {
|
||||
continue;
|
||||
}
|
||||
/** @var Expression<Assign> $currentStmt */
|
||||
$currentStmt = $classMethodStmts[$stmtPosition];
|
||||
$currentStmt = $stmts[$stmtPosition];
|
||||
/** @var Assign $assign */
|
||||
$assign = $currentStmt->expr;
|
||||
if ($this->hasCallLikeInAssignExpr($assign, $scope)) {
|
||||
|
@ -138,12 +139,15 @@ CODE_SAMPLE
|
|||
return $this->sideEffectNodeDetector->detectCallExpr($subNode, $scope);
|
||||
});
|
||||
}
|
||||
private function isVariableUsedInFollowingStmts(ClassMethod $classMethod, int $assignStmtPosition, string $variableName) : bool
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function isVariableUsedInFollowingStmts($functionLike, int $assignStmtPosition, string $variableName) : bool
|
||||
{
|
||||
if ($classMethod->stmts === null) {
|
||||
if ($functionLike->stmts === null) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($classMethod->stmts as $key => $stmt) {
|
||||
foreach ($functionLike->stmts as $key => $stmt) {
|
||||
// do not look yet
|
||||
if ($key <= $assignStmtPosition) {
|
||||
continue;
|
||||
|
@ -160,11 +164,11 @@ CODE_SAMPLE
|
|||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node $node
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function containsCompactFuncCall($node) : bool
|
||||
private function containsCompactFuncCall($functionLike) : bool
|
||||
{
|
||||
$compactFuncCall = $this->betterNodeFinder->findFirst($node, function (Node $node) : bool {
|
||||
$compactFuncCall = $this->betterNodeFinder->findFirst($functionLike, function (Node $node) : bool {
|
||||
if (!$node instanceof FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
|
@ -172,9 +176,12 @@ CODE_SAMPLE
|
|||
});
|
||||
return $compactFuncCall instanceof FuncCall;
|
||||
}
|
||||
private function containsFileIncludes(ClassMethod $classMethod) : bool
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function containsFileIncludes($functionLike) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findInstancesOf($classMethod, [Include_::class]);
|
||||
return (bool) $this->betterNodeFinder->findInstancesOf($functionLike, [Include_::class]);
|
||||
}
|
||||
/**
|
||||
* @param array<int, Stmt> $stmts
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0.18.8';
|
||||
public const PACKAGE_VERSION = '7ec1be6b828042b27e3f40ed41b3285a6fe78502';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-11-14 18:44:59';
|
||||
public const RELEASE_DATE = '2023-11-14 22:16:03';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -504,8 +504,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/container",
|
||||
"version": "v10.31.0",
|
||||
"version_normalized": "10.31.0.0",
|
||||
"version": "v10.32.0",
|
||||
"version_normalized": "10.32.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/container.git",
|
||||
|
@ -561,8 +561,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/contracts",
|
||||
"version": "v10.31.0",
|
||||
"version_normalized": "10.31.0.0",
|
||||
"version": "v10.32.0",
|
||||
"version_normalized": "10.32.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/contracts.git",
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user