From a3cf19f42fe950fc8c8fbaa6f43901719eecde2a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 22 Aug 2024 12:23:28 +0200 Subject: [PATCH] Move preg_match narrowing into specifyTypesForConstantBinaryExpression() --- src/Analyser/TypeSpecifier.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Analyser/TypeSpecifier.php b/src/Analyser/TypeSpecifier.php index 1c1732089d..1f8e46bfbf 100644 --- a/src/Analyser/TypeSpecifier.php +++ b/src/Analyser/TypeSpecifier.php @@ -1130,7 +1130,21 @@ private function specifyTypesForConstantBinaryExpression( return $funcTypes->unionWith($valueTypes); } } + } + if ( + $context->true() + && $exprNode instanceof FuncCall + && $exprNode->name instanceof Name + && $exprNode->name->toLowerString() === 'preg_match' + && (new ConstantIntegerType(1))->isSuperTypeOf($constantType)->yes() + ) { + return $this->specifyTypesInCondition( + $scope, + $exprNode, + $context, + $rootExpr, + ); } return null; @@ -2081,21 +2095,6 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty } $rightType = $scope->getType($rightExpr); - if ( - $context->true() - && $unwrappedLeftExpr instanceof FuncCall - && $unwrappedLeftExpr->name instanceof Name - && $unwrappedLeftExpr->name->toLowerString() === 'preg_match' - && (new ConstantIntegerType(1))->isSuperTypeOf($rightType)->yes() - ) { - return $this->specifyTypesInCondition( - $scope, - $leftExpr, - $context, - $rootExpr, - ); - } - if ( $context->true() && $unwrappedLeftExpr instanceof FuncCall