@@ -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,21 @@ public function specifyTypesInCondition(
466
451
}
467
452
}
468
453
454
+ if (
455
+ !$ context ->null ()
456
+ && $ expr ->right instanceof FuncCall
457
+ ) {
458
+ $ newScope = $ scope ->filterBySpecifiedTypes ($ result );
459
+ $ callType = $ newScope ->getType ($ expr ->right );
460
+ $ newContext = $ this ->createSpecifierContextReturnType ($ callType , $ context );
461
+
462
+ return $ this ->specifyTypesInCondition (
463
+ $ scope ,
464
+ $ expr ->right ,
465
+ $ newContext ,
466
+ )->setRootExpr ($ expr );
467
+ }
468
+
469
469
return $ result ;
470
470
471
471
} elseif ($ expr instanceof Node \Expr \BinaryOp \Greater) {
@@ -1949,6 +1949,20 @@ private function getTypeSpecifyingExtensionsForType(array $extensions, string $c
1949
1949
return array_merge (...$ extensionsForClass );
1950
1950
}
1951
1951
1952
+ private function createSpecifierContextReturnType (
1953
+ Type $ contextReturnType ,
1954
+ TypeSpecifierContext $ context ,
1955
+ ): TypeSpecifierContext
1956
+ {
1957
+ if ($ context ->true ()) {
1958
+ return TypeSpecifierContext::createTrue ($ contextReturnType );
1959
+ } elseif ($ context ->false ()) {
1960
+ return TypeSpecifierContext::createFalse ($ contextReturnType );
1961
+ }
1962
+
1963
+ return $ context ;
1964
+ }
1965
+
1952
1966
public function resolveEqual (Expr \BinaryOp \Equal $ expr , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
1953
1967
{
1954
1968
$ expressions = $ this ->findTypeExpressionsFromBinaryOperation ($ scope , $ expr );
0 commit comments