Skip to content

Commit 5a40963

Browse files
committed
Updated Rector to commit e1d53b058ce5716671651d3e954c6b942d2f4f63
rectorphp/rector-src@e1d53b0 [internal] rename FirstClassCallableRector to ArrayToFirstClassCallableRector to make behavior explicit (#7736)
1 parent 70e1e21 commit 5a40963

20 files changed

+119
-84
lines changed

rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
use PhpParser\NodeVisitor;
2222
use PHPStan\Analyser\Scope;
2323
use PHPStan\Reflection\Annotations\AnnotationMethodReflection;
24-
use PHPStan\Reflection\Native\NativeFunctionReflection;
25-
use PHPStan\Reflection\ParametersAcceptorSelector;
26-
use PHPStan\Type\CallableType;
2724
use Rector\NodeTypeResolver\Node\AttributeKey;
2825
use Rector\PhpParser\AstResolver;
2926
use Rector\PHPStan\ScopeFetcher;
@@ -46,10 +43,6 @@ final class FunctionLikeToFirstClassCallableRector extends AbstractRector implem
4643
* @readonly
4744
*/
4845
private ReflectionResolver $reflectionResolver;
49-
/**
50-
* @var string
51-
*/
52-
private const HAS_CALLBACK_SIGNATURE_MULTI_PARAMS = 'has_callback_signature_multi_params';
5346
public function __construct(AstResolver $astResolver, ReflectionResolver $reflectionResolver)
5447
{
5548
$this->astResolver = $astResolver;
@@ -69,35 +62,13 @@ function ($parameter) {
6962
}
7063
public function getNodeTypes(): array
7164
{
72-
return [CallLike::class, ArrowFunction::class, Closure::class];
65+
return [ArrowFunction::class, Closure::class];
7366
}
7467
/**
75-
* @param CallLike|ArrowFunction|Closure $node
68+
* @param ArrowFunction|Closure $node
7669
*/
7770
public function refactor(Node $node): ?\PhpParser\Node\Expr\CallLike
7871
{
79-
if ($node instanceof CallLike) {
80-
if ($node->isFirstClassCallable()) {
81-
return null;
82-
}
83-
$methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
84-
foreach ($node->getArgs() as $arg) {
85-
if (!$arg->value instanceof Closure && !$arg->value instanceof ArrowFunction) {
86-
continue;
87-
}
88-
if ($methodReflection instanceof NativeFunctionReflection) {
89-
$parametersAcceptors = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants());
90-
foreach ($parametersAcceptors->getParameters() as $extendedParameterReflection) {
91-
if ($extendedParameterReflection->getType() instanceof CallableType && $extendedParameterReflection->getType()->isVariadic()) {
92-
$arg->value->setAttribute(self::HAS_CALLBACK_SIGNATURE_MULTI_PARAMS, \true);
93-
}
94-
}
95-
return null;
96-
}
97-
$arg->value->setAttribute(self::HAS_CALLBACK_SIGNATURE_MULTI_PARAMS, \true);
98-
}
99-
return null;
100-
}
10172
$callLike = $this->extractCallLike($node);
10273
if ($callLike === null) {
10374
return null;
@@ -144,7 +115,7 @@ private function shouldSkip($node, $callLike, Scope $scope): bool
144115
if ($this->isUsingThisInNonObjectContext($callLike, $scope)) {
145116
return \true;
146117
}
147-
if ($node->getAttribute(self::HAS_CALLBACK_SIGNATURE_MULTI_PARAMS) === \true) {
118+
if ($node->getAttribute(AttributeKey::HAS_CLOSURE_WITH_VARIADIC_ARGS) === \true) {
148119
return \true;
149120
}
150121
if ($node->getAttribute(AttributeKey::IS_ASSIGNED_TO) === \true || $node->getAttribute(AttributeKey::IS_BEING_ASSIGNED)) {

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 = 'f632f73e7f0981f4ad52390c4ff9b2166bc04257';
22+
public const PACKAGE_VERSION = 'e1d53b058ce5716671651d3e954c6b942d2f4f63';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-12-08 00:32:31';
27+
public const RELEASE_DATE = '2025-12-08 12:53:51';
2828
/**
2929
* @var int
3030
*/

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,6 @@
9595
use Rector\NodeTypeResolver\NodeTypeResolver\ScalarTypeResolver;
9696
use Rector\NodeTypeResolver\NodeTypeResolver\StaticCallMethodCallTypeResolver;
9797
use Rector\NodeTypeResolver\NodeTypeResolver\TraitTypeResolver;
98-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ArgNodeVisitor;
99-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\AssignedToNodeVisitor;
100-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ByRefReturnNodeVisitor;
101-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ByRefVariableNodeVisitor;
102-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ClassConstFetchNodeVisitor;
103-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ContextNodeVisitor;
104-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\GlobalVariableNodeVisitor;
105-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\NameNodeVisitor;
106-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\PhpVersionConditionNodeVisitor;
107-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\PropertyOrClassConstDefaultNodeVisitor;
108-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
109-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\SymfonyClosureNodeVisitor;
11098
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
11199
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
112100
use Rector\Php80\AttributeDecorator\DoctrineConverterAttributeDecorator;
@@ -127,6 +115,19 @@
127115
use Rector\PhpParser\Comparing\NodeComparator;
128116
use Rector\PhpParser\Node\NodeFactory;
129117
use Rector\PhpParser\NodeTraverser\RectorNodeTraverser;
118+
use Rector\PhpParser\NodeVisitor\ArgNodeVisitor;
119+
use Rector\PhpParser\NodeVisitor\AssignedToNodeVisitor;
120+
use Rector\PhpParser\NodeVisitor\ByRefReturnNodeVisitor;
121+
use Rector\PhpParser\NodeVisitor\ByRefVariableNodeVisitor;
122+
use Rector\PhpParser\NodeVisitor\ClassConstFetchNodeVisitor;
123+
use Rector\PhpParser\NodeVisitor\ClosureWithVariadicParametersNodeVisitor;
124+
use Rector\PhpParser\NodeVisitor\ContextNodeVisitor;
125+
use Rector\PhpParser\NodeVisitor\GlobalVariableNodeVisitor;
126+
use Rector\PhpParser\NodeVisitor\NameNodeVisitor;
127+
use Rector\PhpParser\NodeVisitor\PhpVersionConditionNodeVisitor;
128+
use Rector\PhpParser\NodeVisitor\PropertyOrClassConstDefaultNodeVisitor;
129+
use Rector\PhpParser\NodeVisitor\StaticVariableNodeVisitor;
130+
use Rector\PhpParser\NodeVisitor\SymfonyClosureNodeVisitor;
130131
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
131132
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
132133
use Rector\PHPStanStaticTypeMapper\TypeMapper\AccessoryLiteralStringTypeMapper;
@@ -208,7 +209,7 @@ final class LazyContainerFactory
208209
/**
209210
* @var array<class-string<DecoratingNodeVisitorInterface>>
210211
*/
211-
private const DECORATING_NODE_VISITOR_CLASSES = [ArgNodeVisitor::class, PhpVersionConditionNodeVisitor::class, AssignedToNodeVisitor::class, SymfonyClosureNodeVisitor::class, ByRefReturnNodeVisitor::class, ByRefVariableNodeVisitor::class, ContextNodeVisitor::class, GlobalVariableNodeVisitor::class, NameNodeVisitor::class, StaticVariableNodeVisitor::class, PropertyOrClassConstDefaultNodeVisitor::class, ClassConstFetchNodeVisitor::class];
212+
private const DECORATING_NODE_VISITOR_CLASSES = [ArgNodeVisitor::class, ClosureWithVariadicParametersNodeVisitor::class, PhpVersionConditionNodeVisitor::class, AssignedToNodeVisitor::class, SymfonyClosureNodeVisitor::class, ByRefReturnNodeVisitor::class, ByRefVariableNodeVisitor::class, ContextNodeVisitor::class, GlobalVariableNodeVisitor::class, NameNodeVisitor::class, StaticVariableNodeVisitor::class, PropertyOrClassConstDefaultNodeVisitor::class, ClassConstFetchNodeVisitor::class];
212213
/**
213214
* @var array<class-string<PhpDocTypeMapperInterface>>
214215
*/

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,5 @@ final class AttributeKey
227227
public const IS_INSIDE_BYREF_FUNCTION_LIKE = 'is_inside_byref_function_like';
228228
public const CLASS_CONST_FETCH_NAME = 'class_const_fetch_name';
229229
public const PHP_VERSION_CONDITIONED = 'php_version_conditioned';
230+
public const HAS_CLOSURE_WITH_VARIADIC_ARGS = 'has_closure_with_variadic_args';
230231
}

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ArgNodeVisitor.php renamed to src/PhpParser/NodeVisitor/ArgNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
4+
namespace Rector\PhpParser\NodeVisitor;
55

66
use PhpParser\Node;
77
use PhpParser\Node\Expr\FuncCall;

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php renamed to src/PhpParser/NodeVisitor/AssignedToNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
4+
namespace Rector\PhpParser\NodeVisitor;
55

66
use PhpParser\Node;
77
use PhpParser\Node\ArrayItem;

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php renamed to src/PhpParser/NodeVisitor/ByRefReturnNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
4+
namespace Rector\PhpParser\NodeVisitor;
55

66
use PhpParser\Node;
77
use PhpParser\Node\FunctionLike;

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefVariableNodeVisitor.php renamed to src/PhpParser/NodeVisitor/ByRefVariableNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
4+
namespace Rector\PhpParser\NodeVisitor;
55

66
use PhpParser\Node;
77
use PhpParser\Node\Expr;

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ClassConstFetchNodeVisitor.php renamed to src/PhpParser/NodeVisitor/ClassConstFetchNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
4+
namespace Rector\PhpParser\NodeVisitor;
55

66
use PhpParser\Node;
77
use PhpParser\Node\Expr\ClassConstFetch;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\PhpParser\NodeVisitor;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\Expr\ArrowFunction;
8+
use PhpParser\Node\Expr\CallLike;
9+
use PhpParser\Node\Expr\Closure;
10+
use PhpParser\NodeVisitorAbstract;
11+
use PHPStan\Reflection\Native\NativeFunctionReflection;
12+
use PHPStan\Reflection\ParametersAcceptorSelector;
13+
use PHPStan\Type\CallableType;
14+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
15+
use Rector\NodeTypeResolver\Node\AttributeKey;
16+
use Rector\Reflection\ReflectionResolver;
17+
/**
18+
* Decorate method call, function call or static call, that accepts closure that
19+
* requires multiple args (variadic) - to handle them later in specific rules.
20+
*/
21+
final class ClosureWithVariadicParametersNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
22+
{
23+
/**
24+
* @readonly
25+
*/
26+
private ReflectionResolver $reflectionResolver;
27+
public function __construct(ReflectionResolver $reflectionResolver)
28+
{
29+
$this->reflectionResolver = $reflectionResolver;
30+
}
31+
public function enterNode(Node $node): ?Node
32+
{
33+
if (!$node instanceof CallLike) {
34+
return null;
35+
}
36+
if ($node->isFirstClassCallable()) {
37+
return null;
38+
}
39+
if ($node->getArgs() === []) {
40+
return null;
41+
}
42+
$methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
43+
foreach ($node->getArgs() as $arg) {
44+
if (!$arg->value instanceof Closure && !$arg->value instanceof ArrowFunction) {
45+
continue;
46+
}
47+
if ($methodReflection instanceof NativeFunctionReflection) {
48+
$parametersAcceptors = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants());
49+
foreach ($parametersAcceptors->getParameters() as $extendedParameterReflection) {
50+
if ($extendedParameterReflection->getType() instanceof CallableType && $extendedParameterReflection->getType()->isVariadic()) {
51+
$arg->value->setAttribute(AttributeKey::HAS_CLOSURE_WITH_VARIADIC_ARGS, \true);
52+
}
53+
}
54+
return null;
55+
}
56+
$arg->value->setAttribute(AttributeKey::HAS_CLOSURE_WITH_VARIADIC_ARGS, \true);
57+
}
58+
return null;
59+
}
60+
}

0 commit comments

Comments
 (0)