44
55namespace PHPStanCakePHP2 ;
66
7+ use PhpParser \Node \Expr ;
78use PhpParser \Node \Expr \ClassConstFetch ;
89use PhpParser \Node \Expr \Variable ;
910use PhpParser \Node \Name ;
1011use PhpParser \Node \Scalar \String_ ;
12+ use PHPStan \Type \Constant \ConstantStringType ;
1113use PHPStanCakePHP2 \Service \SchemaService ;
1214use Inflector ;
1315use PhpParser \ConstExprEvaluator ;
@@ -48,27 +50,19 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo
4850
4951 public function getTypeFromStaticMethodCall (MethodReflection $ methodReflection , StaticCall $ methodCall , Scope $ scope ): ?Type
5052 {
51- $ value = $ methodCall ->getArgs ()[0 ]->value ;
53+ $ argumentType = $ scope -> getType ( $ methodCall ->getArgs ()[0 ]->value ) ;
5254
53- if ($ value instanceof Variable) {
54- return new ObjectType ('Model ' );
55- }
56-
57- if ($ value instanceof ClassConstFetch && $ value ->class instanceof Name \FullyQualified) {
58- $ value = new String_ ($ value ->class ->toString ());
59- }
60-
61- $ arg1 = (new ConstExprEvaluator ())->evaluateSilently ($ value );
62-
63- if (! is_string ($ arg1 )) {
55+ if (!$ argumentType instanceof ConstantStringType) {
6456 return $ this ->getDefaultType ();
6557 }
6658
67- if ($ this ->reflectionProvider ->hasClass ($ arg1 )) {
68- return new ObjectType ($ arg1 );
59+ $ value = $ argumentType ->getValue ();
60+
61+ if ($ this ->reflectionProvider ->hasClass ($ value )) {
62+ return new ObjectType ($ value );
6963 }
7064
71- if ($ this ->schemaService ->hasTable (Inflector::tableize ($ arg1 ))) {
65+ if ($ this ->schemaService ->hasTable (Inflector::tableize ($ value ))) {
7266 return new ObjectType ('Model ' );
7367 }
7468
@@ -79,7 +73,7 @@ private function getDefaultType(): Type
7973 {
8074 return new UnionType ([
8175 new BooleanType (),
82- new ObjectWithoutClassType ()
76+ new ObjectWithoutClassType (),
8377 ]);
8478 }
8579}
0 commit comments