@@ -42,10 +42,10 @@ public function getClass(): string
4242
4343 public function isMethodSupported (MethodReflection $ methodReflection ): bool
4444 {
45- return in_array ($ methodReflection ->getName (), ['find ' , 'findAll ' , 'first ' ], true );
45+ return in_array ($ methodReflection ->getName (), ['find ' , 'findAll ' , 'first ' , ' findColumn ' ], true );
4646 }
4747
48- public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
48+ public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): ? Type
4949 {
5050 $ methodName = $ methodReflection ->getName ();
5151
@@ -57,11 +57,44 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
5757 return $ this ->getTypeFromFindAll ($ methodCall , $ scope );
5858 }
5959
60+ if ($ methodName === 'findColumn ' ) {
61+ return $ this ->getTypeFromFindColumn ($ methodCall , $ scope );
62+ }
63+
6064 $ classReflection = $ this ->getClassReflection ($ methodCall , $ scope );
6165
6266 return TypeCombinator::addNull ($ this ->modelFetchedReturnTypeHelper ->getFetchedReturnType ($ classReflection , $ methodCall , $ scope ));
6367 }
6468
69+ private function getTypeFromFindColumn (MethodCall $ methodCall , Scope $ scope ): ?Type
70+ {
71+ $ args = $ methodCall ->getArgs ();
72+
73+ if (! isset ($ args [0 ])) {
74+ return null ;
75+ }
76+
77+ $ strings = $ scope ->getType ($ args [0 ]->value )->getConstantStrings ();
78+
79+ if (count ($ strings ) !== 1 ) {
80+ return null ;
81+ }
82+
83+ $ fieldType = $ this ->modelFetchedReturnTypeHelper ->getColumnFieldType (
84+ $ this ->getClassReflection ($ methodCall , $ scope ),
85+ $ strings [0 ]->getValue (),
86+ );
87+
88+ if ($ fieldType === null ) {
89+ return null ;
90+ }
91+
92+ return TypeCombinator::addNull (TypeCombinator::intersect (
93+ new ArrayType (new IntegerType (), $ fieldType ),
94+ new AccessoryArrayListType (),
95+ ));
96+ }
97+
6598 private function getClassReflection (MethodCall $ methodCall , Scope $ scope ): ClassReflection
6699 {
67100 $ classTypes = $ scope ->getType ($ methodCall ->var )->getObjectClassReflections ();
0 commit comments