2
2
3
3
namespace PHPStan \Type \Php ;
4
4
5
+ use PhpParser \Node \Arg ;
5
6
use PhpParser \Node \Expr \FuncCall ;
6
7
use PHPStan \Analyser \Scope ;
7
8
use PHPStan \Internal \CombinationsHelper ;
@@ -108,6 +109,14 @@ public function getTypeFromFunctionCall(
108
109
$ returnType = new StringType ();
109
110
}
110
111
112
+ return $ this ->getConstantType ($ args , $ returnType , $ functionReflection , $ scope );
113
+ }
114
+
115
+ /**
116
+ * @param Arg[] $args
117
+ */
118
+ private function getConstantType (array $ args , Type $ fallbackReturnType , FunctionReflection $ functionReflection , Scope $ scope ): Type
119
+ {
111
120
$ values = [];
112
121
$ combinationsCount = 1 ;
113
122
foreach ($ args as $ arg ) {
@@ -123,23 +132,23 @@ public function getTypeFromFunctionCall(
123
132
}
124
133
125
134
if (count ($ constantScalarValues ) === 0 ) {
126
- return $ returnType ;
135
+ return $ fallbackReturnType ;
127
136
}
128
137
129
138
$ values [] = $ constantScalarValues ;
130
139
$ combinationsCount *= count ($ constantScalarValues );
131
140
}
132
141
133
142
if ($ combinationsCount > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT ) {
134
- return $ returnType ;
143
+ return $ fallbackReturnType ;
135
144
}
136
145
137
146
$ combinations = CombinationsHelper::combinations ($ values );
138
147
$ returnTypes = [];
139
148
foreach ($ combinations as $ combination ) {
140
149
$ format = array_shift ($ combination );
141
150
if (!is_string ($ format )) {
142
- return $ returnType ;
151
+ return $ fallbackReturnType ;
143
152
}
144
153
145
154
try {
@@ -149,12 +158,12 @@ public function getTypeFromFunctionCall(
149
158
$ returnTypes [] = $ scope ->getTypeFromValue (@vsprintf ($ format , $ combination ));
150
159
}
151
160
} catch (Throwable ) {
152
- return $ returnType ;
161
+ return $ fallbackReturnType ;
153
162
}
154
163
}
155
164
156
165
if (count ($ returnTypes ) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT ) {
157
- return $ returnType ;
166
+ return $ fallbackReturnType ;
158
167
}
159
168
160
169
return TypeCombinator::union (...$ returnTypes );
0 commit comments