mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit 951fb8be8f890b118b87858d45afc93f2cd9a29c
951fb8be8f
[DX] Remove findParentType() method (#4438)
This commit is contained in:
parent
47fc2f5153
commit
830b50116f
@ -43,7 +43,6 @@ use Rector\Core\PhpParser\Parser\SimplePhpParser;
|
||||
use Rector\Core\Util\Reflection\PrivatesAccessor;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php72\NodeManipulator\ClosureNestedUsesDecorator;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
@ -80,11 +79,6 @@ final class AnonymousFunctionFactory
|
||||
* @var \Rector\Core\PhpParser\Parser\SimplePhpParser
|
||||
*/
|
||||
private $simplePhpParser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php72\NodeManipulator\ClosureNestedUsesDecorator
|
||||
*/
|
||||
private $closureNestedUsesDecorator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\AstResolver
|
||||
@ -105,7 +99,7 @@ final class AnonymousFunctionFactory
|
||||
* @see https://regex101.com/r/jkLLlM/2
|
||||
*/
|
||||
private const DIM_FETCH_REGEX = '#(\\$|\\\\|\\x0)(?<number>\\d+)#';
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, NodeFactory $nodeFactory, StaticTypeMapper $staticTypeMapper, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, SimplePhpParser $simplePhpParser, ClosureNestedUsesDecorator $closureNestedUsesDecorator, AstResolver $astResolver, PrivatesAccessor $privatesAccessor, InlineCodeParser $inlineCodeParser)
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, NodeFactory $nodeFactory, StaticTypeMapper $staticTypeMapper, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, SimplePhpParser $simplePhpParser, AstResolver $astResolver, PrivatesAccessor $privatesAccessor, InlineCodeParser $inlineCodeParser)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
@ -113,7 +107,6 @@ final class AnonymousFunctionFactory
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->simplePhpParser = $simplePhpParser;
|
||||
$this->closureNestedUsesDecorator = $closureNestedUsesDecorator;
|
||||
$this->astResolver = $astResolver;
|
||||
$this->privatesAccessor = $privatesAccessor;
|
||||
$this->inlineCodeParser = $inlineCodeParser;
|
||||
@ -127,20 +120,19 @@ final class AnonymousFunctionFactory
|
||||
public function create(array $params, array $stmts, $returnTypeNode, bool $static = \false) : Closure
|
||||
{
|
||||
$useVariables = $this->createUseVariablesFromParams($stmts, $params);
|
||||
$anonymousFunctionNode = new Closure();
|
||||
$anonymousFunctionNode->params = $params;
|
||||
$anonymousFunctionClosure = new Closure();
|
||||
$anonymousFunctionClosure->params = $params;
|
||||
if ($static) {
|
||||
$anonymousFunctionNode->static = $static;
|
||||
$anonymousFunctionClosure->static = $static;
|
||||
}
|
||||
foreach ($useVariables as $useVariable) {
|
||||
$anonymousFunctionNode = $this->closureNestedUsesDecorator->applyNestedUses($anonymousFunctionNode, $useVariable);
|
||||
$anonymousFunctionNode->uses[] = new ClosureUse($useVariable);
|
||||
$anonymousFunctionClosure->uses[] = new ClosureUse($useVariable);
|
||||
}
|
||||
if ($returnTypeNode instanceof Node) {
|
||||
$anonymousFunctionNode->returnType = $returnTypeNode;
|
||||
$anonymousFunctionClosure->returnType = $returnTypeNode;
|
||||
}
|
||||
$anonymousFunctionNode->stmts = $stmts;
|
||||
return $anonymousFunctionNode;
|
||||
$anonymousFunctionClosure->stmts = $stmts;
|
||||
return $anonymousFunctionClosure;
|
||||
}
|
||||
public function createFromPhpMethodReflection(PhpMethodReflection $phpMethodReflection, Expr $expr) : ?Closure
|
||||
{
|
||||
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php72\NodeManipulator;
|
||||
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ClosureUse;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class ClosureNestedUsesDecorator
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver, NodeComparator $nodeComparator)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
}
|
||||
public function applyNestedUses(Closure $anonymousFunctionNode, Variable $useVariable) : Closure
|
||||
{
|
||||
$parentNode = $this->betterNodeFinder->findParentType($useVariable, Closure::class);
|
||||
if (!$parentNode instanceof Closure) {
|
||||
return $anonymousFunctionNode;
|
||||
}
|
||||
$paramNames = $this->nodeNameResolver->getNames($parentNode->params);
|
||||
if ($this->nodeNameResolver->isNames($useVariable, $paramNames)) {
|
||||
return $anonymousFunctionNode;
|
||||
}
|
||||
$anonymousFunctionNode = clone $anonymousFunctionNode;
|
||||
while ($parentNode instanceof Closure) {
|
||||
$parentOfParent = $this->betterNodeFinder->findParentType($parentNode, Closure::class);
|
||||
$uses = [];
|
||||
while ($parentOfParent instanceof Closure) {
|
||||
$uses = $this->collectUsesEqual($parentOfParent, $uses, $useVariable);
|
||||
$parentOfParent = $this->betterNodeFinder->findParentType($parentOfParent, Closure::class);
|
||||
}
|
||||
$uses = \array_merge($parentNode->uses, $uses);
|
||||
$parentNode->uses = $this->cleanClosureUses($uses);
|
||||
$parentNode = $this->betterNodeFinder->findParentType($parentNode, Closure::class);
|
||||
}
|
||||
return $anonymousFunctionNode;
|
||||
}
|
||||
/**
|
||||
* @param ClosureUse[] $uses
|
||||
* @return ClosureUse[]
|
||||
*/
|
||||
private function collectUsesEqual(Closure $closure, array $uses, Variable $useVariable) : array
|
||||
{
|
||||
foreach ($closure->params as $param) {
|
||||
if (!$param->var instanceof Variable) {
|
||||
continue;
|
||||
}
|
||||
if ($this->nodeComparator->areNodesEqual($param->var, $useVariable)) {
|
||||
$uses[] = new ClosureUse($param->var);
|
||||
}
|
||||
}
|
||||
return $uses;
|
||||
}
|
||||
/**
|
||||
* @param ClosureUse[] $uses
|
||||
* @return ClosureUse[]
|
||||
*/
|
||||
private function cleanClosureUses(array $uses) : array
|
||||
{
|
||||
$uniqueUses = [];
|
||||
foreach ($uses as $use) {
|
||||
if (!\is_string($use->var->name)) {
|
||||
continue;
|
||||
}
|
||||
$variableName = $use->var->name;
|
||||
if (\array_key_exists($variableName, $uniqueUses)) {
|
||||
continue;
|
||||
}
|
||||
$uniqueUses[$variableName] = $use;
|
||||
}
|
||||
return \array_values($uniqueUses);
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '651616a14b47aadfd467da1dded6c420f1ef3f01';
|
||||
public const PACKAGE_VERSION = '951fb8be8f890b118b87858d45afc93f2cd9a29c';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-08 21:34:18';
|
||||
public const RELEASE_DATE = '2023-07-08 21:36:04';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -89,24 +89,6 @@ final class BetterNodeFinder
|
||||
$this->currentFileProvider = $currentFileProvider;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
}
|
||||
/**
|
||||
* @deprecated Make use of child nodes instead
|
||||
* @param class-string<T> $type
|
||||
* @template T of Node
|
||||
* @return T|null
|
||||
*/
|
||||
public function findParentType(Node $node, string $type) : ?Node
|
||||
{
|
||||
Assert::isAOf($type, Node::class);
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
while ($parentNode instanceof Node) {
|
||||
if ($parentNode instanceof $type) {
|
||||
return $parentNode;
|
||||
}
|
||||
$parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @template T of Node
|
||||
* @param array<class-string<T>> $types
|
||||
|
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 ComposerAutoloaderInit34da40be8ce4894e423bef751c423d56::getLoader();
|
||||
return ComposerAutoloaderInitc19849416545bf164a97759c7fcc6076::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -2238,7 +2238,6 @@ return array(
|
||||
'Rector\\Php71\\Rector\\TryCatch\\MultiExceptionCatchRector' => $baseDir . '/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php',
|
||||
'Rector\\Php71\\ValueObject\\TwoNodeMatch' => $baseDir . '/rules/Php71/ValueObject/TwoNodeMatch.php',
|
||||
'Rector\\Php72\\NodeFactory\\AnonymousFunctionFactory' => $baseDir . '/rules/Php72/NodeFactory/AnonymousFunctionFactory.php',
|
||||
'Rector\\Php72\\NodeManipulator\\ClosureNestedUsesDecorator' => $baseDir . '/rules/Php72/NodeManipulator/ClosureNestedUsesDecorator.php',
|
||||
'Rector\\Php72\\Rector\\Assign\\ListEachRector' => $baseDir . '/rules/Php72/Rector/Assign/ListEachRector.php',
|
||||
'Rector\\Php72\\Rector\\Assign\\ReplaceEachAssignmentWithKeyCurrentRector' => $baseDir . '/rules/Php72/Rector/Assign/ReplaceEachAssignmentWithKeyCurrentRector.php',
|
||||
'Rector\\Php72\\Rector\\FuncCall\\CreateFunctionToAnonymousFunctionRector' => $baseDir . '/rules/Php72/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php',
|
||||
|
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 ComposerAutoloaderInit34da40be8ce4894e423bef751c423d56
|
||||
class ComposerAutoloaderInitc19849416545bf164a97759c7fcc6076
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit34da40be8ce4894e423bef751c423d56
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit34da40be8ce4894e423bef751c423d56', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitc19849416545bf164a97759c7fcc6076', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit34da40be8ce4894e423bef751c423d56', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitc19849416545bf164a97759c7fcc6076', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit34da40be8ce4894e423bef751c423d56::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitc19849416545bf164a97759c7fcc6076::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit34da40be8ce4894e423bef751c423d56::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitc19849416545bf164a97759c7fcc6076::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit34da40be8ce4894e423bef751c423d56
|
||||
class ComposerStaticInitc19849416545bf164a97759c7fcc6076
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2490,7 +2490,6 @@ class ComposerStaticInit34da40be8ce4894e423bef751c423d56
|
||||
'Rector\\Php71\\Rector\\TryCatch\\MultiExceptionCatchRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php',
|
||||
'Rector\\Php71\\ValueObject\\TwoNodeMatch' => __DIR__ . '/../..' . '/rules/Php71/ValueObject/TwoNodeMatch.php',
|
||||
'Rector\\Php72\\NodeFactory\\AnonymousFunctionFactory' => __DIR__ . '/../..' . '/rules/Php72/NodeFactory/AnonymousFunctionFactory.php',
|
||||
'Rector\\Php72\\NodeManipulator\\ClosureNestedUsesDecorator' => __DIR__ . '/../..' . '/rules/Php72/NodeManipulator/ClosureNestedUsesDecorator.php',
|
||||
'Rector\\Php72\\Rector\\Assign\\ListEachRector' => __DIR__ . '/../..' . '/rules/Php72/Rector/Assign/ListEachRector.php',
|
||||
'Rector\\Php72\\Rector\\Assign\\ReplaceEachAssignmentWithKeyCurrentRector' => __DIR__ . '/../..' . '/rules/Php72/Rector/Assign/ReplaceEachAssignmentWithKeyCurrentRector.php',
|
||||
'Rector\\Php72\\Rector\\FuncCall\\CreateFunctionToAnonymousFunctionRector' => __DIR__ . '/../..' . '/rules/Php72/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php',
|
||||
@ -3081,9 +3080,9 @@ class ComposerStaticInit34da40be8ce4894e423bef751c423d56
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit34da40be8ce4894e423bef751c423d56::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit34da40be8ce4894e423bef751c423d56::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit34da40be8ce4894e423bef751c423d56::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitc19849416545bf164a97759c7fcc6076::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitc19849416545bf164a97759c7fcc6076::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitc19849416545bf164a97759c7fcc6076::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user