From 63adbba259812f0635ce815fa68a61591a0a3fbc Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Tue, 27 Dec 2022 15:39:39 +0100 Subject: [PATCH] Fix `filter_var()` range narrowing of same input type as filter --- src/Type/Php/FilterVarDynamicReturnTypeExtension.php | 2 +- tests/PHPStan/Analyser/data/filter-var.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Type/Php/FilterVarDynamicReturnTypeExtension.php b/src/Type/Php/FilterVarDynamicReturnTypeExtension.php index 240ac36e5f2..7c4dab9c7ee 100644 --- a/src/Type/Php/FilterVarDynamicReturnTypeExtension.php +++ b/src/Type/Php/FilterVarDynamicReturnTypeExtension.php @@ -186,7 +186,7 @@ public function getTypeFromFunctionCall( } } - if ($exactType !== null && !$hasOptions->maybe()) { + if ($exactType !== null && !$hasOptions->maybe() && ($inputType->equals($type) || !$inputType->isSuperTypeOf($type)->yes())) { unset($otherTypes['default']); } diff --git a/tests/PHPStan/Analyser/data/filter-var.php b/tests/PHPStan/Analyser/data/filter-var.php index a08ab1aa10e..ac35a5df947 100644 --- a/tests/PHPStan/Analyser/data/filter-var.php +++ b/tests/PHPStan/Analyser/data/filter-var.php @@ -20,6 +20,7 @@ public function intToInt(int $int, array $options): void { assertType('int', filter_var($int, FILTER_VALIDATE_INT)); assertType('int|false', filter_var($int, FILTER_VALIDATE_INT, $options)); + assertType('int<0, max>|false', filter_var($int, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])); } public function constants(): void