66use PHPStan \Analyser \Scope ;
77use PHPStan \DependencyInjection \AutowiredService ;
88use PHPStan \Reflection \FunctionReflection ;
9+ use PHPStan \Type \Accessory \AccessoryNonFalsyStringType ;
910use PHPStan \Type \BenevolentUnionType ;
1011use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
1112use PHPStan \Type \FloatType ;
13+ use PHPStan \Type \IntersectionType ;
1214use PHPStan \Type \MixedType ;
1315use PHPStan \Type \StringType ;
1416use PHPStan \Type \Type ;
@@ -26,8 +28,10 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
2628
2729 public function getTypeFromFunctionCall (FunctionReflection $ functionReflection , FuncCall $ functionCall , Scope $ scope ): Type
2830 {
31+ $ stringType = new IntersectionType ([new StringType (), new AccessoryNonFalsyStringType ()]);
32+
2933 if (count ($ functionCall ->getArgs ()) < 1 ) {
30- return new StringType () ;
34+ return $ stringType ;
3135 }
3236
3337 $ argType = $ scope ->getType ($ functionCall ->getArgs ()[0 ]->value );
@@ -38,14 +42,14 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
3842 return new FloatType ();
3943 }
4044 if ($ compareTypes === $ isFalseType ) {
41- return new StringType () ;
45+ return $ stringType ;
4246 }
4347
4448 if ($ argType instanceof MixedType) {
45- return new BenevolentUnionType ([new StringType () , new FloatType ()]);
49+ return new BenevolentUnionType ([$ stringType , new FloatType ()]);
4650 }
4751
48- return new UnionType ([new StringType () , new FloatType ()]);
52+ return new UnionType ([$ stringType , new FloatType ()]);
4953 }
5054
5155}
0 commit comments