@@ -57,7 +57,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
5757 if ($ splitLengthType instanceof ConstantIntegerType) {
5858 $ splitLength = $ splitLengthType ->getValue ();
5959 if ($ splitLength < 1 ) {
60- return new ConstantBooleanType (false );
60+ return $ this -> phpVersion -> throwsValueErrorForInternalFunctions () ? null : new ConstantBooleanType (false );
6161 }
6262 }
6363 } else {
@@ -70,21 +70,19 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
7070 $ strings = $ scope ->getType ($ functionCall ->getArgs ()[2 ]->value )->getConstantStrings ();
7171 $ values = array_unique (array_map (static fn (ConstantStringType $ encoding ): string => $ encoding ->getValue (), $ strings ));
7272
73- if (count ($ values ) !== 1 ) {
74- return null ;
75- }
76-
77- $ encoding = $ values [0 ];
78- if (!$ this ->isSupportedEncoding ($ encoding )) {
79- return new ConstantBooleanType (false );
73+ if (count ($ values ) === 1 ) {
74+ $ encoding = $ values [0 ];
75+ if (!$ this ->isSupportedEncoding ($ encoding )) {
76+ return $ this ->phpVersion ->throwsValueErrorForInternalFunctions () ? null : new ConstantBooleanType (false );
77+ }
8078 }
8179 } else {
8280 $ encoding = mb_internal_encoding ();
8381 }
8482 }
8583
8684 $ stringType = $ scope ->getType ($ functionCall ->getArgs ()[0 ]->value );
87- if (isset ($ splitLength )) {
85+ if (isset ($ splitLength ) && ( $ functionReflection -> getName () === ' str_split ' || null !== $ encoding ) ) {
8886 $ constantStrings = $ stringType ->getConstantStrings ();
8987 if (count ($ constantStrings ) > 0 ) {
9088 $ results = [];
@@ -118,10 +116,14 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
118116 $ returnValueType = TypeCombinator::intersect (new StringType (), ...$ valueTypes );
119117
120118 $ returnType = AccessoryArrayListType::intersectWith (TypeCombinator::intersect (new ArrayType (new IntegerType (), $ returnValueType )));
119+ if ($ isInputNonEmptyString || ($ encoding === null && !$ this ->phpVersion ->strSplitReturnsEmptyArray ())) {
120+ $ returnType = TypeCombinator::intersect ($ returnType , new NonEmptyArrayType ());
121+ }
122+ if (!isset ($ splitLength ) && !$ this ->phpVersion ->throwsValueErrorForInternalFunctions ()) {
123+ $ returnType = TypeCombinator::union ($ returnType , new ConstantBooleanType (false ));
124+ }
121125
122- return $ isInputNonEmptyString || ($ encoding === null && !$ this ->phpVersion ->strSplitReturnsEmptyArray ())
123- ? TypeCombinator::intersect ($ returnType , new NonEmptyArrayType ())
124- : $ returnType ;
126+ return $ returnType ;
125127 }
126128
127129 /**
0 commit comments