Skip to content

Commit

Permalink
Fix filter_var() range narrowing of same input type as filter
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Dec 27, 2022
1 parent 86523f8 commit 63adbba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/Php/FilterVarDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/data/filter-var.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63adbba

Please sign in to comment.