@@ -242,11 +242,11 @@ public function specifyTypesInCondition(
242242 $ expr ->left instanceof FuncCall
243243 && count ($ expr ->left ->getArgs ()) >= 1
244244 && $ expr ->left ->name instanceof Name
245- && in_array (strtolower ((string ) $ expr ->left ->name ), ['count ' , 'sizeof ' , 'strlen ' , 'mb_strlen ' ], true )
245+ && in_array (strtolower ((string ) $ expr ->left ->name ), ['count ' , 'sizeof ' , 'strlen ' , 'mb_strlen ' , ' preg_match ' ], true )
246246 && (
247247 !$ expr ->right instanceof FuncCall
248248 || !$ expr ->right ->name instanceof Name
249- || !in_array (strtolower ((string ) $ expr ->right ->name ), ['count ' , 'sizeof ' , 'strlen ' , 'mb_strlen ' ], true )
249+ || !in_array (strtolower ((string ) $ expr ->right ->name ), ['count ' , 'sizeof ' , 'strlen ' , 'mb_strlen ' , ' preg_match ' ], true )
250250 )
251251 ) {
252252 $ inverseOperator = $ expr instanceof Node \Expr \BinaryOp \Smaller
@@ -336,6 +336,22 @@ public function specifyTypesInCondition(
336336 }
337337 }
338338
339+ if (
340+ !$ context ->null ()
341+ && $ expr ->right instanceof FuncCall
342+ && count ($ expr ->right ->getArgs ()) === 3
343+ && $ expr ->right ->name instanceof Name
344+ && in_array (strtolower ((string ) $ expr ->right ->name ), ['preg_match ' ], true )
345+ && IntegerRangeType::fromInterval (0 , null )->isSuperTypeOf ($ leftType )->yes ()
346+ ) {
347+ return $ this ->specifyTypesInCondition (
348+ $ scope ,
349+ new Expr \BinaryOp \NotIdentical ($ expr ->right , new ConstFetch (new Name ('false ' ))),
350+ $ context ,
351+ $ rootExpr ,
352+ );
353+ }
354+
339355 if (
340356 !$ context ->null ()
341357 && $ expr ->right instanceof FuncCall
0 commit comments