4
4
5
5
namespace PHPStanCakePHP2 ;
6
6
7
+ use PhpParser \Node \Expr ;
7
8
use PhpParser \Node \Expr \ClassConstFetch ;
8
9
use PhpParser \Node \Expr \Variable ;
9
10
use PhpParser \Node \Name ;
10
11
use PhpParser \Node \Scalar \String_ ;
12
+ use PHPStan \Type \Constant \ConstantStringType ;
11
13
use PHPStanCakePHP2 \Service \SchemaService ;
12
14
use Inflector ;
13
15
use PhpParser \ConstExprEvaluator ;
@@ -48,27 +50,19 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo
48
50
49
51
public function getTypeFromStaticMethodCall (MethodReflection $ methodReflection , StaticCall $ methodCall , Scope $ scope ): ?Type
50
52
{
51
- $ value = $ methodCall ->getArgs ()[0 ]->value ;
53
+ $ argumentType = $ scope -> getType ( $ methodCall ->getArgs ()[0 ]->value ) ;
52
54
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) {
64
56
return $ this ->getDefaultType ();
65
57
}
66
58
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 );
69
63
}
70
64
71
- if ($ this ->schemaService ->hasTable (Inflector::tableize ($ arg1 ))) {
65
+ if ($ this ->schemaService ->hasTable (Inflector::tableize ($ value ))) {
72
66
return new ObjectType ('Model ' );
73
67
}
74
68
@@ -79,7 +73,7 @@ private function getDefaultType(): Type
79
73
{
80
74
return new UnionType ([
81
75
new BooleanType (),
82
- new ObjectWithoutClassType ()
76
+ new ObjectWithoutClassType (),
83
77
]);
84
78
}
85
79
}
0 commit comments