1212use PhpParser \Node \Expr \PropertyFetch ;
1313use PhpParser \Node \Expr \StaticCall ;
1414use PhpParser \Node \Expr \Variable ;
15- use PhpParser \Node \Stmt \ClassConst ;
16- use PhpParser \Node \Stmt \Property ;
1715use PhpParser \Node \VariadicPlaceholder ;
1816use PhpParser \NodeVisitor ;
1917use PHPStan \Analyser \Scope ;
2018use PHPStan \Reflection \ClassReflection ;
2119use PHPStan \Reflection \ReflectionProvider ;
2220use Rector \NodeCollector \NodeAnalyzer \ArrayCallableMethodMatcher ;
2321use Rector \NodeCollector \ValueObject \ArrayCallable ;
22+ use Rector \NodeTypeResolver \Node \AttributeKey ;
2423use Rector \PHPStan \ScopeFetcher ;
2524use Rector \Rector \AbstractRector ;
2625use Rector \Reflection \ReflectionResolver ;
3231use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
3332
3433/**
34+ * @see RFC https://wiki.php.net/rfc/first_class_callable_syntax
3535 * @see \Rector\Tests\Php81\Rector\Array_\FirstClassCallableRector\FirstClassCallableRectorTest
3636 */
3737final class FirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface
@@ -46,7 +46,6 @@ public function __construct(
4646
4747 public function getRuleDefinition (): RuleDefinition
4848 {
49- // see RFC https://wiki.php.net/rfc/first_class_callable_syntax
5049 return new RuleDefinition ('Upgrade array callable to first class callable ' , [
5150 new CodeSample (
5251 <<<'CODE_SAMPLE'
@@ -86,14 +85,14 @@ public function name()
8685 */
8786 public function getNodeTypes (): array
8887 {
89- return [Property::class, ClassConst::class, Array_::class, Closure::class];
88+ return [Array_::class, Closure::class];
9089 }
9190
9291 /**
93- * @param Property|ClassConst| Array_|Closure $node
92+ * @param Array_|Closure $node
9493 * @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
9594 */
96- public function refactor (Node $ node ): int | null | StaticCall |MethodCall
95+ public function refactor (Node $ node ): StaticCall |MethodCall | null | int
9796 {
9897 if ($ node instanceof Closure) {
9998 if ($ this ->symfonyPhpClosureDetector ->detect ($ node )) {
@@ -103,10 +102,6 @@ public function refactor(Node $node): int|null|StaticCall|MethodCall
103102 return null ;
104103 }
105104
106- if ($ node instanceof Property || $ node instanceof ClassConst) {
107- return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
108- }
109-
110105 $ scope = ScopeFetcher::fetch ($ node );
111106
112107 $ arrayCallable = $ this ->arrayCallableMethodMatcher ->match ($ node , $ scope );
@@ -119,6 +114,14 @@ public function refactor(Node $node): int|null|StaticCall|MethodCall
119114 return null ;
120115 }
121116
117+ if ($ node ->getAttribute (AttributeKey::IS_CLASS_CONST_VALUE )) {
118+ return null ;
119+ }
120+
121+ if ($ node ->getAttribute (AttributeKey::IS_DEFAULT_PROPERTY_VALUE )) {
122+ return null ;
123+ }
124+
122125 $ args = [new VariadicPlaceholder ()];
123126 if ($ callerExpr instanceof ClassConstFetch) {
124127 $ type = $ this ->getType ($ callerExpr ->class );
0 commit comments