Skip to content

Commit 6ceaceb

Browse files
committed
Update TypeSpecifier.php
1 parent a70580c commit 6ceaceb

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,21 +331,6 @@ public function specifyTypesInCondition(
331331
}
332332
}
333333

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-
349334
if (
350335
!$context->null()
351336
&& $expr->right instanceof FuncCall
@@ -466,6 +451,21 @@ public function specifyTypesInCondition(
466451
}
467452
}
468453

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+
469469
return $result;
470470

471471
} elseif ($expr instanceof Node\Expr\BinaryOp\Greater) {
@@ -1949,6 +1949,20 @@ private function getTypeSpecifyingExtensionsForType(array $extensions, string $c
19491949
return array_merge(...$extensionsForClass);
19501950
}
19511951

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+
19521966
public function resolveEqual(Expr\BinaryOp\Equal $expr, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes
19531967
{
19541968
$expressions = $this->findTypeExpressionsFromBinaryOperation($scope, $expr);

0 commit comments

Comments
 (0)