Updated Rector to commit e8151293d5a25a776c73dd73eeed461c26dc7e6b

e8151293d5 Remove PARENT_NODE from CatchExceptionNameMatchingTypeRector (#3990)
This commit is contained in:
Tomas Votruba 2023-05-27 10:47:14 +00:00
parent 0256872962
commit ffca1acc2d
5 changed files with 32 additions and 40 deletions

View File

@ -14,6 +14,7 @@ use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
@ -126,7 +127,7 @@ CODE_SAMPLE
return null;
}
$catch->var = new Variable($newVariableName);
$this->renameVariableInStmts($catch, $stmt, $oldVariableName, $newVariableName, $key, $node->stmts, $node->stmts[$key + 1] ?? null);
$this->renameVariableInStmts($catch, $oldVariableName, $newVariableName, $key, $node->stmts, $node->stmts[$key + 1] ?? null);
$hasChanged = \true;
}
if ($hasChanged) {
@ -159,7 +160,7 @@ CODE_SAMPLE
/**
* @param Stmt[] $stmts
*/
private function renameVariableInStmts(Catch_ $catch, TryCatch $tryCatch, string $oldVariableName, string $newVariableName, int $key, array $stmts, ?Stmt $stmt) : void
private function renameVariableInStmts(Catch_ $catch, string $oldVariableName, string $newVariableName, int $key, array $stmts, ?Stmt $stmt) : void
{
$this->traverseNodesWithCallable($catch->stmts, function (Node $node) use($oldVariableName, $newVariableName) {
if (!$node instanceof Variable) {
@ -171,50 +172,41 @@ CODE_SAMPLE
$node->name = $newVariableName;
return null;
});
$this->replaceNextUsageVariable($tryCatch, $oldVariableName, $newVariableName, $key, $stmts, $stmt);
$this->replaceNextUsageVariable($oldVariableName, $newVariableName, $key, $stmts, $stmt);
}
/**
* @param Stmt[] $stmts
*/
private function replaceNextUsageVariable(Node $currentNode, string $oldVariableName, string $newVariableName, int $key, array $stmts, ?Node $nextNode) : void
private function replaceNextUsageVariable(string $oldVariableName, string $newVariableName, int $key, array $stmts, ?Node $nextNode) : void
{
if (!$nextNode instanceof Node) {
return;
}
/** @var Variable[] $variables */
$variables = $this->betterNodeFinder->find($nextNode, function (Node $node) use($oldVariableName) : bool {
if (!$node instanceof Variable) {
return \false;
$nonAssignedVariables = [];
$this->traverseNodesWithCallable($nextNode, function (Node $node) use($oldVariableName, &$nonAssignedVariables) : ?int {
if ($node instanceof Assign && $node->var instanceof Variable) {
return NodeTraverser::STOP_TRAVERSAL;
}
return $this->nodeNameResolver->isName($node, $oldVariableName);
if (!$node instanceof Variable) {
return null;
}
if (!$this->nodeNameResolver->isName($node, $oldVariableName)) {
return null;
}
$nonAssignedVariables[] = $node;
return null;
});
$processRenameVariables = $this->processRenameVariable($variables, $oldVariableName, $newVariableName);
if (!$processRenameVariables) {
return;
foreach ($nonAssignedVariables as $nonAssignedVariable) {
$nonAssignedVariable->name = $newVariableName;
}
if (!isset($stmts[$key + 1])) {
return;
}
$currentNode = $stmts[$key + 1];
if (!isset($stmts[$key + 2])) {
return;
}
$nextNode = $stmts[$key + 2];
$key += 2;
$this->replaceNextUsageVariable($currentNode, $oldVariableName, $newVariableName, $key, $stmts, $nextNode);
}
/**
* @param Variable[] $variables
*/
private function processRenameVariable(array $variables, string $oldVariableName, string $newVariableName) : bool
{
foreach ($variables as $variable) {
$parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Assign && $this->nodeComparator->areNodesEqual($parentNode->var, $variable) && $this->nodeNameResolver->isName($parentNode->var, $oldVariableName) && !$this->nodeComparator->areNodesEqual($parentNode->expr, $variable)) {
return \false;
}
$variable->name = $newVariableName;
}
return \true;
$this->replaceNextUsageVariable($oldVariableName, $newVariableName, $key, $stmts, $nextNode);
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'fdf11bab10f9e7e1d63b4e0dba1325b947391e5d';
public const PACKAGE_VERSION = 'e8151293d5a25a776c73dd73eeed461c26dc7e6b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-27 10:34:59';
public const RELEASE_DATE = '2023-05-27 10:43:22';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit3e83712edbcb7a626236ec5135aec8cd::getLoader();
return ComposerAutoloaderInitde370b15480e42f0d942cef2fd8a1269::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit3e83712edbcb7a626236ec5135aec8cd
class ComposerAutoloaderInitde370b15480e42f0d942cef2fd8a1269
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit3e83712edbcb7a626236ec5135aec8cd
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit3e83712edbcb7a626236ec5135aec8cd', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitde370b15480e42f0d942cef2fd8a1269', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit3e83712edbcb7a626236ec5135aec8cd', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitde370b15480e42f0d942cef2fd8a1269', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitde370b15480e42f0d942cef2fd8a1269::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitde370b15480e42f0d942cef2fd8a1269::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd
class ComposerStaticInitde370b15480e42f0d942cef2fd8a1269
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3089,9 +3089,9 @@ class ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3e83712edbcb7a626236ec5135aec8cd::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitde370b15480e42f0d942cef2fd8a1269::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitde370b15480e42f0d942cef2fd8a1269::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitde370b15480e42f0d942cef2fd8a1269::$classMap;
}, null, ClassLoader::class);
}