mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Updated Rector to commit fc423fd69f9a96932ae62d09c6f01812678651cc
fc423fd69f
[NodeTypeResolver] Add ContextNodeVisitor to remove parent lookup on inside loop detection (#4270)
This commit is contained in:
parent
a80b7eaeaf
commit
10dcb93b50
@ -8,7 +8,7 @@ use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNestingScope\ValueObject\ControlStructure;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
final class ContextAnalyzer
|
||||
{
|
||||
/**
|
||||
@ -27,16 +27,7 @@ final class ContextAnalyzer
|
||||
}
|
||||
public function isInLoop(Node $node) : bool
|
||||
{
|
||||
$firstParent = $this->betterNodeFinder->findParentByTypes($node, \array_merge(ControlStructure::LOOP_NODES, self::BREAK_NODES));
|
||||
if (!$firstParent instanceof Node) {
|
||||
return \false;
|
||||
}
|
||||
foreach (ControlStructure::LOOP_NODES as $type) {
|
||||
if (\is_a($firstParent, $type, \true)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
return $node->getAttribute(AttributeKey::IS_IN_LOOP) === \true;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
|
@ -184,4 +184,8 @@ final class AttributeKey
|
||||
* @var string
|
||||
*/
|
||||
public const STATEMENT_DEPTH = 'statementDepth';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const IS_IN_LOOP = 'is_in_loop';
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Break_;
|
||||
use PhpParser\Node\Stmt\Do_;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\While_;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser)
|
||||
{
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
}
|
||||
public function enterNode(Node $node) : ?Node
|
||||
{
|
||||
if ($node instanceof For_ || $node instanceof Foreach_ || $node instanceof While_ || $node instanceof Do_) {
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($node->stmts, static function (Node $subNode) {
|
||||
if ($subNode instanceof If_ || $subNode instanceof Break_) {
|
||||
$subNode->setAttribute(AttributeKey::IS_IN_LOOP, \true);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '3d07c26d3efc4c0c16cbbe1fb347114e0178cc5e';
|
||||
public const PACKAGE_VERSION = 'fc423fd69f9a96932ae62d09c6f01812678651cc';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-18 05:17:36';
|
||||
public const RELEASE_DATE = '2023-06-18 12:57:12';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit1ad8de2918e609488bd217ece42ce5c0::getLoader();
|
||||
return ComposerAutoloaderInitbcd345f54a340521d99a0a0b7daad710::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -2030,6 +2030,7 @@ return array(
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\AssignedToNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\ByRefReturnNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\ByRefVariableNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefVariableNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\ContextNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\GlobalVariableNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/GlobalVariableNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\RemoveDeepChainMethodCallNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/RemoveDeepChainMethodCallNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\StaticVariableNodeVisitor' => $baseDir . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StaticVariableNodeVisitor.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 ComposerAutoloaderInit1ad8de2918e609488bd217ece42ce5c0
|
||||
class ComposerAutoloaderInitbcd345f54a340521d99a0a0b7daad710
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit1ad8de2918e609488bd217ece42ce5c0
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1ad8de2918e609488bd217ece42ce5c0', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitbcd345f54a340521d99a0a0b7daad710', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1ad8de2918e609488bd217ece42ce5c0', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitbcd345f54a340521d99a0a0b7daad710', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitbcd345f54a340521d99a0a0b7daad710::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitbcd345f54a340521d99a0a0b7daad710::$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 ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0
|
||||
class ComposerStaticInitbcd345f54a340521d99a0a0b7daad710
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2281,6 +2281,7 @@ class ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\AssignedToNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\ByRefReturnNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\ByRefVariableNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefVariableNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\ContextNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\GlobalVariableNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/GlobalVariableNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\RemoveDeepChainMethodCallNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/RemoveDeepChainMethodCallNodeVisitor.php',
|
||||
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\StaticVariableNodeVisitor' => __DIR__ . '/../..' . '/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StaticVariableNodeVisitor.php',
|
||||
@ -3094,9 +3095,9 @@ class ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1ad8de2918e609488bd217ece42ce5c0::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitbcd345f54a340521d99a0a0b7daad710::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitbcd345f54a340521d99a0a0b7daad710::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitbcd345f54a340521d99a0a0b7daad710::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user