Updated Rector to commit 3b6084dec770faeb7fca657b6f1ab6898a0801d5

3b6084dec7 [Php72] Remove parent attribute on AnonymousFunctionFactory (#4443)
This commit is contained in:
Tomas Votruba 2023-07-09 01:45:20 +00:00
parent d701c75713
commit 0e1f48fb00
8 changed files with 45 additions and 20 deletions

View File

@ -192,6 +192,10 @@ final class AttributeKey
* @var string
*/
public const IS_IN_LOOP = 'is_in_loop';
/**
* @var string
*/
public const IS_VARIABLE_LOOP = 'is_variable_loop';
/**
* @var string
*/
@ -240,6 +244,10 @@ final class AttributeKey
* @var string
*/
public const IS_ARG_VALUE = 'is_arg_value';
/**
* @var string
*/
public const IS_PARAM_VAR = 'IS_PARAM_VAR';
/**
* @var string
*/

View File

@ -11,6 +11,8 @@ use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Do_;
@ -53,12 +55,8 @@ final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResol
return null;
}
if ($node instanceof Attribute) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->args, static function (Node $subNode) {
if ($subNode instanceof Array_) {
$subNode->setAttribute(AttributeKey::IS_ARRAY_IN_ATTRIBUTE, \true);
}
return null;
});
$this->processContextInAttribute($node);
return null;
}
if ($node instanceof If_ || $node instanceof Else_ || $node instanceof ElseIf_) {
$this->processContextInIf($node);
@ -70,8 +68,20 @@ final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResol
if ($node instanceof Arg) {
$node->value->setAttribute(AttributeKey::IS_ARG_VALUE, \true);
}
if ($node instanceof Param) {
$node->var->setAttribute(AttributeKey::IS_PARAM_VAR, \true);
}
return null;
}
private function processContextInAttribute(Attribute $attribute) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($attribute->args, static function (Node $subNode) {
if ($subNode instanceof Array_) {
$subNode->setAttribute(AttributeKey::IS_ARRAY_IN_ATTRIBUTE, \true);
}
return null;
});
}
/**
* @param \PhpParser\Node\Expr\Isset_|\PhpParser\Node\Stmt\Unset_ $node
*/
@ -103,6 +113,12 @@ final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResol
*/
private function processContextInLoop($node) : void
{
if ($node instanceof Foreach_) {
if ($node->keyVar instanceof Variable) {
$node->keyVar->setAttribute(AttributeKey::IS_VARIABLE_LOOP, \true);
}
$node->valueVar->setAttribute(AttributeKey::IS_VARIABLE_LOOP, \true);
}
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->stmts, static function (Node $subNode) : ?int {
if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;

View File

@ -222,8 +222,7 @@ final class AnonymousFunctionFactory
if (\in_array($variableName, $paramNames, \true)) {
continue;
}
$parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Node && \in_array(\get_class($parentNode), [Assign::class, Foreach_::class, Param::class], \true)) {
if ($variable->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === \true || $variable->getAttribute(AttributeKey::IS_PARAM_VAR) === \true || $variable->getAttribute(AttributeKey::IS_VARIABLE_LOOP) === \true) {
$alreadyAssignedVariables[] = $variableName;
}
if (!$this->nodeNameResolver->isNames($variable, $alreadyAssignedVariables)) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'c7a7046b05c0cfba50aa245973f42a00009540ad';
public const PACKAGE_VERSION = '3b6084dec770faeb7fca657b6f1ab6898a0801d5';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-07-09 00:34:38';
public const RELEASE_DATE = '2023-07-09 08:41:16';
/**
* @var int
*/

View File

@ -8,6 +8,7 @@ use PhpParser\Node\Stmt;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use Rector\Core\PhpParser\NodeTraverser\NodeConnectingTraverser;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\AssignedToNodeVisitor;
final class SimplePhpParser
{
/**
@ -25,6 +26,7 @@ final class SimplePhpParser
$this->nodeConnectingTraverser = $nodeConnectingTraverser;
$parserFactory = new ParserFactory();
$this->phpParser = $parserFactory->create(ParserFactory::PREFER_PHP7);
$this->nodeConnectingTraverser->addVisitor(new AssignedToNodeVisitor());
}
/**
* @api tests

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit696c37db7fa7b44637af01a6abf5a84e
class ComposerAutoloaderInit15c88e4ebae2c19fc397915fb68d3e7c
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit696c37db7fa7b44637af01a6abf5a84e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit696c37db7fa7b44637af01a6abf5a84e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit15c88e4ebae2c19fc397915fb68d3e7c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit696c37db7fa7b44637af01a6abf5a84e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit15c88e4ebae2c19fc397915fb68d3e7c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit15c88e4ebae2c19fc397915fb68d3e7c::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit15c88e4ebae2c19fc397915fb68d3e7c::$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 ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e
class ComposerStaticInit15c88e4ebae2c19fc397915fb68d3e7c
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3077,9 +3077,9 @@ class ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit696c37db7fa7b44637af01a6abf5a84e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit15c88e4ebae2c19fc397915fb68d3e7c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit15c88e4ebae2c19fc397915fb68d3e7c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit15c88e4ebae2c19fc397915fb68d3e7c::$classMap;
}, null, ClassLoader::class);
}