mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
Updated Rector to commit f4f9d5c771017ccf1ca99f30efcdb0e71ebcc22c
f4f9d5c771
[Php71] Remove parent lookup on AssignArrayToStringRector (#4302)
This commit is contained in:
parent
577f0343f5
commit
0b8bae3feb
@ -10,12 +10,12 @@ use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -59,17 +59,38 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Assign::class, Class_::class];
|
||||
return [Namespace_::class, FileWithoutNamespace::class, ClassMethod::class, Function_::class];
|
||||
}
|
||||
/**
|
||||
* @param Assign|Class_ $node
|
||||
* @param Namespace_|FileWithoutNamespace|ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($node instanceof Class_) {
|
||||
return $this->refactorClass($node);
|
||||
if ($node->stmts === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->refactorAssign($node);
|
||||
$hasChanged = \false;
|
||||
$this->traverseNodesWithCallable($node->stmts, function (Node $subNode) use(&$hasChanged, $node) : ?int {
|
||||
if ($subNode instanceof Assign) {
|
||||
$assign = $this->refactorAssign($subNode, $node);
|
||||
if ($assign instanceof Assign) {
|
||||
$hasChanged = \true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($subNode instanceof Class_) {
|
||||
$class = $this->refactorClass($subNode);
|
||||
if ($class instanceof Class_) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function isEmptyString(Expr $expr) : bool
|
||||
{
|
||||
@ -109,12 +130,11 @@ CODE_SAMPLE
|
||||
}
|
||||
/**
|
||||
* @return ArrayDimFetch[]
|
||||
* @param \PhpParser\Node\Stmt\Namespace_|\Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
|
||||
*/
|
||||
private function findSameNamedVariableAssigns(Variable $variable) : array
|
||||
private function findSameNamedVariableAssigns(Variable $variable, $node) : array
|
||||
{
|
||||
// assign of empty string to something
|
||||
$scopeStmt = $this->findParentScope($variable);
|
||||
if (!$scopeStmt instanceof Stmt) {
|
||||
if ($node->stmts === null) {
|
||||
return [];
|
||||
}
|
||||
$variableName = $this->nodeNameResolver->getName($variable);
|
||||
@ -122,7 +142,7 @@ CODE_SAMPLE
|
||||
return [];
|
||||
}
|
||||
$assignedArrayDimFetches = [];
|
||||
$this->traverseNodesWithCallable($scopeStmt, function (Node $node) use($variableName, &$assignedArrayDimFetches) {
|
||||
$this->traverseNodesWithCallable($node->stmts, function (Node $node) use($variableName, &$assignedArrayDimFetches) {
|
||||
if (!$node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
@ -141,13 +161,9 @@ CODE_SAMPLE
|
||||
return $assignedArrayDimFetches;
|
||||
}
|
||||
/**
|
||||
* @return Function_|ClassMethod|Class_|Namespace_|null
|
||||
* @param \PhpParser\Node\Stmt\Namespace_|\Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
|
||||
*/
|
||||
private function findParentScope(Variable $variable)
|
||||
{
|
||||
return $this->betterNodeFinder->findParentByTypes($variable, [Function_::class, ClassMethod::class, Class_::class, Namespace_::class]);
|
||||
}
|
||||
private function refactorAssign(Assign $assign) : ?Assign
|
||||
private function refactorAssign(Assign $assign, $node) : ?Assign
|
||||
{
|
||||
if (!$this->isEmptyString($assign->expr)) {
|
||||
return null;
|
||||
@ -155,7 +171,7 @@ CODE_SAMPLE
|
||||
if (!$assign->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
$variableAssignArrayDimFetches = $this->findSameNamedVariableAssigns($assign->var);
|
||||
$variableAssignArrayDimFetches = $this->findSameNamedVariableAssigns($assign->var, $node);
|
||||
$shouldRetype = \false;
|
||||
// detect if is part of variable assign?
|
||||
foreach ($variableAssignArrayDimFetches as $variableAssignArrayDimFetch) {
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '57e2712bd04d491826cc60afa9e003c54e8add96';
|
||||
public const PACKAGE_VERSION = 'f4f9d5c771017ccf1ca99f30efcdb0e71ebcc22c';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-20 08:30:58';
|
||||
public const RELEASE_DATE = '2023-06-20 08:45:57';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite43434694c102827ca61c8b125ba1969::getLoader();
|
||||
return ComposerAutoloaderInitfdb1eba100fd05b864785447606068f7::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite43434694c102827ca61c8b125ba1969
|
||||
class ComposerAutoloaderInitfdb1eba100fd05b864785447606068f7
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInite43434694c102827ca61c8b125ba1969
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite43434694c102827ca61c8b125ba1969', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitfdb1eba100fd05b864785447606068f7', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite43434694c102827ca61c8b125ba1969', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitfdb1eba100fd05b864785447606068f7', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite43434694c102827ca61c8b125ba1969::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitfdb1eba100fd05b864785447606068f7::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite43434694c102827ca61c8b125ba1969::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitfdb1eba100fd05b864785447606068f7::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite43434694c102827ca61c8b125ba1969
|
||||
class ComposerStaticInitfdb1eba100fd05b864785447606068f7
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3097,9 +3097,9 @@ class ComposerStaticInite43434694c102827ca61c8b125ba1969
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite43434694c102827ca61c8b125ba1969::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite43434694c102827ca61c8b125ba1969::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite43434694c102827ca61c8b125ba1969::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitfdb1eba100fd05b864785447606068f7::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitfdb1eba100fd05b864785447606068f7::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitfdb1eba100fd05b864785447606068f7::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user