Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type a ranged value for filter_var(FILTER_VALIDATE_INT) #1443

Merged
merged 6 commits into from Jun 22, 2022
Merged

Type a ranged value for filter_var(FILTER_VALIDATE_INT) #1443

merged 6 commits into from Jun 22, 2022

Conversation

zonuexe
Copy link
Contributor

@zonuexe zonuexe commented Jun 19, 2022

$this->filterTypeOptions = [
$this->getConstant('FILTER_VALIDATE_INT') => ['min_range', 'max_range'],
// PHPStan does not yet support FloatRangeType
// $this->getConstant('FILTER_VALIDATE_FLOAT') => ['min_range', 'max_range'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't plan to use it immediately, but it is possible to make FloatRangeType with -INF <= float <= INF.

$otherTypes = $this->getOtherTypes($flagsArg, $scope, $typeOptionNames);

if ($inputType->isNonEmptyString()->yes()
&& $type instanceof StringType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$type->isString()->yes()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed e301f6d

if ($inputType->isNonEmptyString()->yes()
&& $type instanceof StringType
&& !$this->canStringBeSanitized($filterValue, $flagsArg, $scope)) {
$type = new IntersectionType([$type, new AccessoryNonEmptyStringType()]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeCombinator::intersect() instead please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed fec2ef6

}

if (isset($otherTypes['default']) && $otherTypes['default']->isSuperTypeOf($type)->no()) {
$type = new UnionType([$type, $otherTypes['default']]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeCombinator::union() please

if (isset($range['min']) || isset($range['max'])) {
$min = isset($range['min']) && is_int($range['min']) ? $range['min'] : null;
$max = isset($range['max']) && is_int($range['max']) ? $range['max'] : null;
$otherTypes['range'] = new IntegerRangeType($min, $max);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntegerRangeType::fromInterval() please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 09ae197

@ondrejmirtes ondrejmirtes merged commit 79e18f3 into phpstan:1.7.x Jun 22, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@zonuexe zonuexe deleted the feature/typing-filter_var-range branch June 22, 2022 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants