1111use PhpParser \Node \Expr \PropertyFetch ;
1212use PhpParser \Node \Expr \StaticCall ;
1313use PhpParser \Node \Expr \Variable ;
14- use PhpParser \Node \Stmt \ClassConst ;
15- use PhpParser \Node \Stmt \Property ;
1614use PhpParser \Node \VariadicPlaceholder ;
1715use PhpParser \NodeVisitor ;
1816use PHPStan \Analyser \Scope ;
1917use PHPStan \Reflection \ClassReflection ;
2018use PHPStan \Reflection \ReflectionProvider ;
2119use Rector \NodeCollector \NodeAnalyzer \ArrayCallableMethodMatcher ;
2220use Rector \NodeCollector \ValueObject \ArrayCallable ;
21+ use Rector \NodeTypeResolver \Node \AttributeKey ;
2322use Rector \PHPStan \ScopeFetcher ;
2423use Rector \Rector \AbstractRector ;
2524use Rector \Reflection \ReflectionResolver ;
3029use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
3130use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
3231/**
32+ * @see RFC https://wiki.php.net/rfc/first_class_callable_syntax
3333 * @see \Rector\Tests\Php81\Rector\Array_\FirstClassCallableRector\FirstClassCallableRectorTest
3434 */
3535final class FirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface
@@ -59,7 +59,6 @@ public function __construct(ArrayCallableMethodMatcher $arrayCallableMethodMatch
5959 }
6060 public function getRuleDefinition (): RuleDefinition
6161 {
62- // see RFC https://wiki.php.net/rfc/first_class_callable_syntax
6362 return new RuleDefinition ('Upgrade array callable to first class callable ' , [new CodeSample (<<<'CODE_SAMPLE'
6463final class SomeClass
6564{
@@ -93,10 +92,10 @@ public function name()
9392 */
9493 public function getNodeTypes (): array
9594 {
96- return [Property::class, ClassConst::class, Array_::class, Closure::class];
95+ return [Array_::class, Closure::class];
9796 }
9897 /**
99- * @param Property|ClassConst| Array_|Closure $node
98+ * @param Array_|Closure $node
10099 * @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
101100 */
102101 public function refactor (Node $ node )
@@ -107,9 +106,6 @@ public function refactor(Node $node)
107106 }
108107 return null ;
109108 }
110- if ($ node instanceof Property || $ node instanceof ClassConst) {
111- return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
112- }
113109 $ scope = ScopeFetcher::fetch ($ node );
114110 $ arrayCallable = $ this ->arrayCallableMethodMatcher ->match ($ node , $ scope );
115111 if (!$ arrayCallable instanceof ArrayCallable) {
@@ -119,6 +115,12 @@ public function refactor(Node $node)
119115 if (!$ callerExpr instanceof Variable && !$ callerExpr instanceof PropertyFetch && !$ callerExpr instanceof ClassConstFetch) {
120116 return null ;
121117 }
118+ if ($ node ->getAttribute (AttributeKey::IS_CLASS_CONST_VALUE )) {
119+ return null ;
120+ }
121+ if ($ node ->getAttribute (AttributeKey::IS_DEFAULT_PROPERTY_VALUE )) {
122+ return null ;
123+ }
122124 $ args = [new VariadicPlaceholder ()];
123125 if ($ callerExpr instanceof ClassConstFetch) {
124126 $ type = $ this ->getType ($ callerExpr ->class );
0 commit comments