@@ -210,18 +210,31 @@ public function specifyTypesInCondition(
210
210
}
211
211
}
212
212
213
+ if (count ($ rightType ->getConstantStrings ()) > 0 ) {
214
+ $ types = null ;
215
+ foreach ($ rightType ->getConstantStrings () as $ constantString ) {
216
+ $ specifiedType = $ this ->specifyTypesForConstantStringBinaryExpression ($ unwrappedLeftExpr , $ constantString , $ context , $ scope , $ rootExpr );
217
+ if ($ specifiedType === null ) {
218
+ continue ;
219
+ }
220
+ if ($ types === null ) {
221
+ $ types = $ specifiedType ;
222
+ continue ;
223
+ }
224
+
225
+ $ types = $ types ->intersectWith ($ specifiedType );
226
+ }
227
+
228
+ if ($ types !== null ) {
229
+ return $ types ;
230
+ }
231
+ }
232
+
213
233
$ expressions = $ this ->findTypeExpressionsFromBinaryOperation ($ scope , $ expr );
214
234
if ($ expressions !== null ) {
215
235
$ exprNode = $ expressions [0 ];
216
236
$ constantType = $ expressions [1 ];
217
237
218
- if ($ constantType instanceof ConstantStringType) {
219
- $ specifiedType = $ this ->specifyTypesForConstantStringBinaryExpression ($ exprNode , $ constantType , $ context , $ scope , $ rootExpr );
220
- if ($ specifiedType !== null ) {
221
- return $ specifiedType ;
222
- }
223
- }
224
-
225
238
$ specifiedType = $ this ->specifyTypesForConstantBinaryExpression ($ exprNode , $ constantType , $ context , $ scope , $ rootExpr );
226
239
if ($ specifiedType !== null ) {
227
240
return $ specifiedType ;
@@ -1065,11 +1078,6 @@ private function specifyTypesForConstantStringBinaryExpression(
1065
1078
?Expr $ rootExpr ,
1066
1079
): ?SpecifiedTypes
1067
1080
{
1068
- $ unwrappedExprNode = $ exprNode ;
1069
- if ($ exprNode instanceof AlwaysRememberedExpr) {
1070
- $ unwrappedExprNode = $ exprNode ->getExpr ();
1071
- }
1072
-
1073
1081
if (
1074
1082
$ context ->truthy ()
1075
1083
&& $ exprNode instanceof FuncCall
@@ -1102,10 +1110,10 @@ private function specifyTypesForConstantStringBinaryExpression(
1102
1110
}
1103
1111
1104
1112
if (
1105
- $ unwrappedExprNode instanceof FuncCall
1106
- && $ unwrappedExprNode ->name instanceof Name
1107
- && strtolower ($ unwrappedExprNode ->name ->toString ()) === 'gettype '
1108
- && isset ($ unwrappedExprNode ->getArgs ()[0 ])
1113
+ $ exprNode instanceof FuncCall
1114
+ && $ exprNode ->name instanceof Name
1115
+ && strtolower ($ exprNode ->name ->toString ()) === 'gettype '
1116
+ && isset ($ exprNode ->getArgs ()[0 ])
1109
1117
) {
1110
1118
$ type = null ;
1111
1119
if ($ constantType ->getValue () === 'string ' ) {
@@ -1134,8 +1142,8 @@ private function specifyTypesForConstantStringBinaryExpression(
1134
1142
}
1135
1143
1136
1144
if ($ type !== null ) {
1137
- $ callType = $ this ->create ($ unwrappedExprNode , $ constantType , $ context , false , $ scope , $ rootExpr );
1138
- $ argType = $ this ->create ($ unwrappedExprNode ->getArgs ()[0 ]->value , $ type , $ context , false , $ scope , $ rootExpr );
1145
+ $ callType = $ this ->create ($ exprNode , $ constantType , $ context , false , $ scope , $ rootExpr );
1146
+ $ argType = $ this ->create ($ exprNode ->getArgs ()[0 ]->value , $ type , $ context , false , $ scope , $ rootExpr );
1139
1147
return $ callType ->unionWith ($ argType );
1140
1148
}
1141
1149
}
0 commit comments