@@ -331,21 +331,6 @@ public function specifyTypesInCondition(
331
331
}
332
332
}
333
333
334
- if (
335
- !$ context ->null ()
336
- && $ expr ->right instanceof FuncCall
337
- && count ($ expr ->right ->getArgs ()) >= 3
338
- && $ expr ->right ->name instanceof Name
339
- && in_array (strtolower ((string ) $ expr ->right ->name ), ['preg_match ' ], true )
340
- && IntegerRangeType::fromInterval (0 , null )->isSuperTypeOf ($ leftType )->yes ()
341
- ) {
342
- return $ this ->specifyTypesInCondition (
343
- $ scope ,
344
- new Expr \BinaryOp \NotIdentical ($ expr ->right , new ConstFetch (new Name ('false ' ))),
345
- $ context ,
346
- )->setRootExpr ($ expr );
347
- }
348
-
349
334
if (
350
335
!$ context ->null ()
351
336
&& $ expr ->right instanceof FuncCall
@@ -466,6 +451,27 @@ public function specifyTypesInCondition(
466
451
}
467
452
}
468
453
454
+ if (
455
+ !$ context ->null ()
456
+ && $ expr ->left instanceof Node \Scalar
457
+ && $ expr ->right instanceof Expr \FuncCall
458
+ && $ expr ->right ->name instanceof Name
459
+ && in_array (strtolower ((string ) $ expr ->right ->name ), ['preg_match ' ], true )
460
+ ) {
461
+ if (!$ scope instanceof MutatingScope) {
462
+ throw new ShouldNotHappenException ();
463
+ }
464
+ $ newScope = $ scope ->filterBySpecifiedTypes ($ result );
465
+ $ callType = $ newScope ->getType ($ expr ->right );
466
+ $ newContext = $ context ->newWithReturnType ($ callType );
467
+
468
+ $ result = $ result ->unionWith ($ this ->specifyTypesInCondition (
469
+ $ scope ,
470
+ $ expr ->right ,
471
+ $ newContext ,
472
+ )->setRootExpr ($ expr ));
473
+ }
474
+
469
475
return $ result ;
470
476
471
477
} elseif ($ expr instanceof Node \Expr \BinaryOp \Greater) {
0 commit comments