77use PhpParser \Node ;
88use PhpParser \Node \Expr \Array_ ;
99use PhpParser \Node \Expr \ClassConstFetch ;
10+ use PhpParser \Node \Expr \Closure ;
1011use PhpParser \Node \Expr \MethodCall ;
1112use PhpParser \Node \Expr \PropertyFetch ;
1213use PhpParser \Node \Expr \StaticCall ;
2425use Rector \Rector \AbstractRector ;
2526use Rector \Reflection \ReflectionResolver ;
2627use Rector \StaticTypeMapper \ValueObject \Type \FullyQualifiedObjectType ;
28+ use Rector \Symfony \NodeAnalyzer \SymfonyPhpClosureDetector ;
2729use Rector \ValueObject \PhpVersion ;
2830use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
2931use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -37,7 +39,8 @@ final class FirstClassCallableRector extends AbstractRector implements MinPhpVer
3739 public function __construct (
3840 private readonly ArrayCallableMethodMatcher $ arrayCallableMethodMatcher ,
3941 private readonly ReflectionProvider $ reflectionProvider ,
40- private readonly ReflectionResolver $ reflectionResolver
42+ private readonly ReflectionResolver $ reflectionResolver ,
43+ private readonly SymfonyPhpClosureDetector $ symfonyPhpClosureDetector
4144 ) {
4245 }
4346
@@ -83,15 +86,19 @@ public function name()
8386 */
8487 public function getNodeTypes (): array
8588 {
86- return [Property::class, ClassConst::class, Array_::class];
89+ return [Property::class, ClassConst::class, Array_::class, Closure::class ];
8790 }
8891
8992 /**
90- * @param Property|ClassConst|Array_ $node
93+ * @param Property|ClassConst|Array_|Closure $node
9194 * @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
9295 */
9396 public function refactor (Node $ node ): int |null |StaticCall |MethodCall
9497 {
98+ if ($ node instanceof Closure && $ this ->symfonyPhpClosureDetector ->detect ($ node )) {
99+ return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
100+ }
101+
95102 if ($ node instanceof Property || $ node instanceof ClassConst) {
96103 return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
97104 }
0 commit comments