55use PhpParser \Node \Expr \FuncCall ;
66use PHPStan \Analyser \Scope ;
77use PHPStan \Reflection \FunctionReflection ;
8+ use PHPStan \Type \Accessory \AccessoryLowercaseStringType ;
9+ use PHPStan \Type \Accessory \AccessoryUppercaseStringType ;
810use PHPStan \Type \ClassStringType ;
911use PHPStan \Type \Constant \ConstantStringType ;
1012use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
13+ use PHPStan \Type \IntersectionType ;
14+ use PHPStan \Type \StringType ;
1115use PHPStan \Type \Type ;
1216use function count ;
1317use function ltrim ;
@@ -22,11 +26,29 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
2226
2327 public function getTypeFromFunctionCall (FunctionReflection $ functionReflection , FuncCall $ functionCall , Scope $ scope ): ?Type
2428 {
25- if (count ($ functionCall ->getArgs ()) !== 2 ) {
29+ if (count ($ functionCall ->getArgs ()) < 1 ) {
2630 return null ;
2731 }
2832
2933 $ string = $ scope ->getType ($ functionCall ->getArgs ()[0 ]->value );
34+
35+ $ accessory = [];
36+ $ defaultType = new StringType ();
37+ if ($ string ->isLowercaseString ()->yes ()) {
38+ $ accessory [] = new AccessoryLowercaseStringType ();
39+ }
40+ if ($ string ->isUppercaseString ()->yes ()) {
41+ $ accessory [] = new AccessoryUppercaseStringType ();
42+ }
43+ if (count ($ accessory ) > 0 ) {
44+ $ accessory [] = new StringType ();
45+ $ defaultType = new IntersectionType ($ accessory );
46+ }
47+
48+ if (count ($ functionCall ->getArgs ()) !== 2 ) {
49+ return $ defaultType ;
50+ }
51+
3052 $ trimChars = $ scope ->getType ($ functionCall ->getArgs ()[1 ]->value );
3153
3254 if ($ trimChars instanceof ConstantStringType && $ trimChars ->getValue () === '\\' && $ string ->isClassString ()->yes ()) {
@@ -37,7 +59,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
3759 return new ClassStringType ();
3860 }
3961
40- return null ;
62+ return $ defaultType ;
4163 }
4264
4365}
0 commit comments