@@ -48,11 +48,12 @@ public function getTypeFromFunctionCall(
48
48
return null ;
49
49
}
50
50
51
- $ formatType = $ scope -> getType ($ args[ 0 ]-> value );
52
- if (count ( $ args ) === 1 ) {
53
- return $ this -> getConstantType ( $ args , null , $ functionReflection , $ scope ) ;
51
+ $ constantType = $ this -> getConstantType ($ args, $ functionReflection , $ scope );
52
+ if ($ constantType !== null ) {
53
+ return $ constantType ;
54
54
}
55
55
56
+ $ formatType = $ scope ->getType ($ args [0 ]->value );
56
57
$ formatStrings = $ formatType ->getConstantStrings ();
57
58
if (count ($ formatStrings ) === 0 ) {
58
59
return null ;
@@ -118,19 +119,19 @@ public function getTypeFromFunctionCall(
118
119
$ returnType = new StringType ();
119
120
}
120
121
121
- return $ this -> getConstantType ( $ args , $ returnType, $ functionReflection , $ scope ) ;
122
+ return $ returnType ;
122
123
}
123
124
124
125
/**
125
126
* @param Arg[] $args
126
127
*/
127
- private function getConstantType (array $ args , ? Type $ fallbackReturnType , FunctionReflection $ functionReflection , Scope $ scope ): ?Type
128
+ private function getConstantType (array $ args , FunctionReflection $ functionReflection , Scope $ scope ): ?Type
128
129
{
129
130
$ values = [];
130
131
$ combinationsCount = 1 ;
131
132
foreach ($ args as $ arg ) {
132
133
if ($ arg ->unpack ) {
133
- return $ fallbackReturnType ;
134
+ return null ;
134
135
}
135
136
136
137
$ argType = $ scope ->getType ($ arg ->value );
@@ -145,23 +146,23 @@ private function getConstantType(array $args, ?Type $fallbackReturnType, Functio
145
146
}
146
147
147
148
if (count ($ constantScalarValues ) === 0 ) {
148
- return $ fallbackReturnType ;
149
+ return null ;
149
150
}
150
151
151
152
$ values [] = $ constantScalarValues ;
152
153
$ combinationsCount *= count ($ constantScalarValues );
153
154
}
154
155
155
156
if ($ combinationsCount > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT ) {
156
- return $ fallbackReturnType ;
157
+ return null ;
157
158
}
158
159
159
160
$ combinations = CombinationsHelper::combinations ($ values );
160
161
$ returnTypes = [];
161
162
foreach ($ combinations as $ combination ) {
162
163
$ format = array_shift ($ combination );
163
164
if (!is_string ($ format )) {
164
- return $ fallbackReturnType ;
165
+ return null ;
165
166
}
166
167
167
168
try {
@@ -171,12 +172,12 @@ private function getConstantType(array $args, ?Type $fallbackReturnType, Functio
171
172
$ returnTypes [] = $ scope ->getTypeFromValue (@vsprintf ($ format , $ combination ));
172
173
}
173
174
} catch (Throwable ) {
174
- return $ fallbackReturnType ;
175
+ return null ;
175
176
}
176
177
}
177
178
178
179
if (count ($ returnTypes ) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT ) {
179
- return $ fallbackReturnType ;
180
+ return null ;
180
181
}
181
182
182
183
return TypeCombinator::union (...$ returnTypes );
0 commit comments