Skip to content

Commit a3cf19f

Browse files
committed
Move preg_match narrowing into specifyTypesForConstantBinaryExpression()
1 parent bbd64a9 commit a3cf19f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,21 @@ private function specifyTypesForConstantBinaryExpression(
11301130
return $funcTypes->unionWith($valueTypes);
11311131
}
11321132
}
1133+
}
11331134

1135+
if (
1136+
$context->true()
1137+
&& $exprNode instanceof FuncCall
1138+
&& $exprNode->name instanceof Name
1139+
&& $exprNode->name->toLowerString() === 'preg_match'
1140+
&& (new ConstantIntegerType(1))->isSuperTypeOf($constantType)->yes()
1141+
) {
1142+
return $this->specifyTypesInCondition(
1143+
$scope,
1144+
$exprNode,
1145+
$context,
1146+
$rootExpr,
1147+
);
11341148
}
11351149

11361150
return null;
@@ -2081,21 +2095,6 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
20812095
}
20822096
$rightType = $scope->getType($rightExpr);
20832097

2084-
if (
2085-
$context->true()
2086-
&& $unwrappedLeftExpr instanceof FuncCall
2087-
&& $unwrappedLeftExpr->name instanceof Name
2088-
&& $unwrappedLeftExpr->name->toLowerString() === 'preg_match'
2089-
&& (new ConstantIntegerType(1))->isSuperTypeOf($rightType)->yes()
2090-
) {
2091-
return $this->specifyTypesInCondition(
2092-
$scope,
2093-
$leftExpr,
2094-
$context,
2095-
$rootExpr,
2096-
);
2097-
}
2098-
20992098
if (
21002099
$context->true()
21012100
&& $unwrappedLeftExpr instanceof FuncCall

0 commit comments

Comments
 (0)