Skip to content

Commit 3b34749

Browse files
committed
Updated Rector to commit 8cd3cc67b4abbc92256490f9ddc2f5f96124af4b
rectorphp/rector-src@8cd3cc6 Remove direct NodeTravser::* where possible, use node visitor attribute key instead (#7697)
1 parent 63abe8e commit 3b34749

File tree

11 files changed

+62
-37
lines changed

11 files changed

+62
-37
lines changed

rules/Php81/Rector/Array_/FirstClassCallableRector.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
use PhpParser\Node;
77
use PhpParser\Node\Expr\Array_;
88
use PhpParser\Node\Expr\ClassConstFetch;
9-
use PhpParser\Node\Expr\Closure;
109
use PhpParser\Node\Expr\MethodCall;
1110
use PhpParser\Node\Expr\PropertyFetch;
1211
use PhpParser\Node\Expr\StaticCall;
1312
use PhpParser\Node\Expr\Variable;
1413
use PhpParser\Node\VariadicPlaceholder;
15-
use PhpParser\NodeVisitor;
1614
use PHPStan\Analyser\Scope;
1715
use PHPStan\Reflection\ClassReflection;
1816
use PHPStan\Reflection\ReflectionProvider;
@@ -23,7 +21,6 @@
2321
use Rector\Rector\AbstractRector;
2422
use Rector\Reflection\ReflectionResolver;
2523
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
26-
use Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector;
2724
use Rector\ValueObject\PhpVersion;
2825
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
2926
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -46,16 +43,11 @@ final class FirstClassCallableRector extends AbstractRector implements MinPhpVer
4643
* @readonly
4744
*/
4845
private ReflectionResolver $reflectionResolver;
49-
/**
50-
* @readonly
51-
*/
52-
private SymfonyPhpClosureDetector $symfonyPhpClosureDetector;
53-
public function __construct(ArrayCallableMethodMatcher $arrayCallableMethodMatcher, ReflectionProvider $reflectionProvider, ReflectionResolver $reflectionResolver, SymfonyPhpClosureDetector $symfonyPhpClosureDetector)
46+
public function __construct(ArrayCallableMethodMatcher $arrayCallableMethodMatcher, ReflectionProvider $reflectionProvider, ReflectionResolver $reflectionResolver)
5447
{
5548
$this->arrayCallableMethodMatcher = $arrayCallableMethodMatcher;
5649
$this->reflectionProvider = $reflectionProvider;
5750
$this->reflectionResolver = $reflectionResolver;
58-
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
5951
}
6052
public function getRuleDefinition(): RuleDefinition
6153
{
@@ -92,18 +84,15 @@ public function name()
9284
*/
9385
public function getNodeTypes(): array
9486
{
95-
return [Array_::class, Closure::class];
87+
return [Array_::class];
9688
}
9789
/**
98-
* @param Array_|Closure $node
99-
* @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
90+
* @param Array_ $node
91+
* @return \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|null
10092
*/
10193
public function refactor(Node $node)
10294
{
103-
if ($node instanceof Closure) {
104-
if ($this->symfonyPhpClosureDetector->detect($node)) {
105-
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
106-
}
95+
if ($node->getAttribute(AttributeKey::IS_INSIDE_SYMFONY_PHP_CLOSURE)) {
10796
return null;
10897
}
10998
$scope = ScopeFetcher::fetch($node);

rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\ArrayDimFetch;
1010
use PhpParser\Node\Expr\Assign;
11-
use PhpParser\Node\Expr\AssignOp;
1211
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
1312
use PhpParser\Node\Expr\Isset_;
1413
use PhpParser\Node\Expr\MethodCall;
@@ -51,18 +50,14 @@ public function getRuleDefinition(): RuleDefinition
5150
}
5251
public function getNodeTypes(): array
5352
{
54-
return [AssignOp::class, Assign::class, Isset_::class, Unset_::class, ArrayDimFetch::class];
53+
return [Assign::class, Isset_::class, Unset_::class, ArrayDimFetch::class];
5554
}
5655
/**
57-
* @template TNode of ArrayDimFetch|Assign|Isset_|Unset_
58-
* @param TNode $node
56+
* @param ArrayDimFetch|Assign|Isset_|Unset_ $node
5957
* @return ($node is Unset_ ? Stmt[]|int : ($node is Isset_ ? Expr|int : MethodCall|int|null))
6058
*/
6159
public function refactor(Node $node)
6260
{
63-
if ($node instanceof AssignOp) {
64-
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
65-
}
6661
if ($node instanceof Unset_) {
6762
return $this->handleUnset($node);
6863
}
@@ -79,6 +74,9 @@ public function refactor(Node $node)
7974
if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED)) {
8075
return null;
8176
}
77+
if ($node->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR)) {
78+
return null;
79+
}
8280
return $this->createExplicitMethodCall($node, 'get');
8381
}
8482
public function configure(array $configuration): void

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '3f60b07605cbbea6be4a6e5936b202310c092668';
22+
public const PACKAGE_VERSION = '8cd3cc67b4abbc92256490f9ddc2f5f96124af4b';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-12-02 00:32:30';
27+
public const RELEASE_DATE = '2025-12-02 01:43:32';
2828
/**
2929
* @var int
3030
*/

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\NameNodeVisitor;
104104
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\PropertyOrClassConstDefaultNodeVisitor;
105105
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
106+
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\SymfonyClosureNodeVisitor;
106107
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
107108
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
108109
use Rector\Php80\AttributeDecorator\DoctrineConverterAttributeDecorator;
@@ -204,7 +205,7 @@ final class LazyContainerFactory
204205
/**
205206
* @var array<class-string<DecoratingNodeVisitorInterface>>
206207
*/
207-
private const DECORATING_NODE_VISITOR_CLASSES = [ArgNodeVisitor::class, AssignedToNodeVisitor::class, ByRefReturnNodeVisitor::class, ByRefVariableNodeVisitor::class, ContextNodeVisitor::class, GlobalVariableNodeVisitor::class, NameNodeVisitor::class, StaticVariableNodeVisitor::class, PropertyOrClassConstDefaultNodeVisitor::class];
208+
private const DECORATING_NODE_VISITOR_CLASSES = [ArgNodeVisitor::class, AssignedToNodeVisitor::class, SymfonyClosureNodeVisitor::class, ByRefReturnNodeVisitor::class, ByRefVariableNodeVisitor::class, ContextNodeVisitor::class, GlobalVariableNodeVisitor::class, NameNodeVisitor::class, StaticVariableNodeVisitor::class, PropertyOrClassConstDefaultNodeVisitor::class];
208209
/**
209210
* @var array<class-string<PhpDocTypeMapperInterface>>
210211
*/

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,5 @@ final class AttributeKey
237237
public const HAS_MERGED_COMMENTS = 'has_merged_comments';
238238
public const IS_DEFAULT_PROPERTY_VALUE = 'is_default_property_value';
239239
public const IS_CLASS_CONST_VALUE = 'is_default_class_const_value';
240+
public const IS_INSIDE_SYMFONY_PHP_CLOSURE = 'is_inside_symfony_php_closure';
240241
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\Expr\Closure;
8+
use PhpParser\NodeVisitorAbstract;
9+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
10+
use Rector\NodeTypeResolver\Node\AttributeKey;
11+
use Rector\PhpParser\NodeTraverser\SimpleTraverser;
12+
use Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector;
13+
final class SymfonyClosureNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
14+
{
15+
/**
16+
* @readonly
17+
*/
18+
private SymfonyPhpClosureDetector $symfonyPhpClosureDetector;
19+
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector)
20+
{
21+
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
22+
}
23+
public function enterNode(Node $node): ?Node
24+
{
25+
if (!$node instanceof Closure) {
26+
return null;
27+
}
28+
if (!$this->symfonyPhpClosureDetector->detect($node)) {
29+
return null;
30+
}
31+
SimpleTraverser::decorateWithTrueAttribute($node, AttributeKey::IS_INSIDE_SYMFONY_PHP_CLOSURE);
32+
return null;
33+
}
34+
}

vendor/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
require_once __DIR__ . '/composer/autoload_real.php';
2121

22-
return ComposerAutoloaderInita05020a1ba1c38c2596fcbea78eb7e22::getLoader();
22+
return ComposerAutoloaderInitd7faddeaafe22cf1903ddfcba3e7de0e::getLoader();

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,7 @@
18391839
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\NameNodeVisitor' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/NameNodeVisitor.php',
18401840
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\PropertyOrClassConstDefaultNodeVisitor' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/PropertyOrClassConstDefaultNodeVisitor.php',
18411841
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\StaticVariableNodeVisitor' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StaticVariableNodeVisitor.php',
1842+
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\SymfonyClosureNodeVisitor' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/SymfonyClosureNodeVisitor.php',
18421843
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\PHPStanNodeScopeResolver' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php',
18431844
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\RectorNodeScopeResolver' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/RectorNodeScopeResolver.php',
18441845
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\ScopeFactory' => $baseDir . '/src/NodeTypeResolver/PHPStan/Scope/ScopeFactory.php',

vendor/composer/autoload_real.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// autoload_real.php @generated by Composer
44

5-
class ComposerAutoloaderInita05020a1ba1c38c2596fcbea78eb7e22
5+
class ComposerAutoloaderInitd7faddeaafe22cf1903ddfcba3e7de0e
66
{
77
private static $loader;
88

@@ -22,17 +22,17 @@ public static function getLoader()
2222
return self::$loader;
2323
}
2424

25-
spl_autoload_register(array('ComposerAutoloaderInita05020a1ba1c38c2596fcbea78eb7e22', 'loadClassLoader'), true, true);
25+
spl_autoload_register(array('ComposerAutoloaderInitd7faddeaafe22cf1903ddfcba3e7de0e', 'loadClassLoader'), true, true);
2626
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27-
spl_autoload_unregister(array('ComposerAutoloaderInita05020a1ba1c38c2596fcbea78eb7e22', 'loadClassLoader'));
27+
spl_autoload_unregister(array('ComposerAutoloaderInitd7faddeaafe22cf1903ddfcba3e7de0e', 'loadClassLoader'));
2828

2929
require __DIR__ . '/autoload_static.php';
30-
call_user_func(\Composer\Autoload\ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22::getInitializer($loader));
30+
call_user_func(\Composer\Autoload\ComposerStaticInitd7faddeaafe22cf1903ddfcba3e7de0e::getInitializer($loader));
3131

3232
$loader->setClassMapAuthoritative(true);
3333
$loader->register(true);
3434

35-
$filesToLoad = \Composer\Autoload\ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22::$files;
35+
$filesToLoad = \Composer\Autoload\ComposerStaticInitd7faddeaafe22cf1903ddfcba3e7de0e::$files;
3636
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
3737
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
3838
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

vendor/composer/autoload_static.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Composer\Autoload;
66

7-
class ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22
7+
class ComposerStaticInitd7faddeaafe22cf1903ddfcba3e7de0e
88
{
99
public static $files = array (
1010
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
@@ -2087,6 +2087,7 @@ class ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22
20872087
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\NameNodeVisitor' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/NameNodeVisitor.php',
20882088
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\PropertyOrClassConstDefaultNodeVisitor' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/PropertyOrClassConstDefaultNodeVisitor.php',
20892089
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\StaticVariableNodeVisitor' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StaticVariableNodeVisitor.php',
2090+
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\NodeVisitor\\SymfonyClosureNodeVisitor' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/SymfonyClosureNodeVisitor.php',
20902091
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\PHPStanNodeScopeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php',
20912092
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\RectorNodeScopeResolver' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/RectorNodeScopeResolver.php',
20922093
'Rector\\NodeTypeResolver\\PHPStan\\Scope\\ScopeFactory' => __DIR__ . '/../..' . '/src/NodeTypeResolver/PHPStan/Scope/ScopeFactory.php',
@@ -3188,9 +3189,9 @@ class ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22
31883189
public static function getInitializer(ClassLoader $loader)
31893190
{
31903191
return \Closure::bind(function () use ($loader) {
3191-
$loader->prefixLengthsPsr4 = ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22::$prefixLengthsPsr4;
3192-
$loader->prefixDirsPsr4 = ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22::$prefixDirsPsr4;
3193-
$loader->classMap = ComposerStaticInita05020a1ba1c38c2596fcbea78eb7e22::$classMap;
3192+
$loader->prefixLengthsPsr4 = ComposerStaticInitd7faddeaafe22cf1903ddfcba3e7de0e::$prefixLengthsPsr4;
3193+
$loader->prefixDirsPsr4 = ComposerStaticInitd7faddeaafe22cf1903ddfcba3e7de0e::$prefixDirsPsr4;
3194+
$loader->classMap = ComposerStaticInitd7faddeaafe22cf1903ddfcba3e7de0e::$classMap;
31943195

31953196
}, null, ClassLoader::class);
31963197
}

0 commit comments

Comments
 (0)