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
Type a ranged value for filter_var(FILTER_VALIDATE_INT) #1443
Conversation
$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'], |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$type->isString()->yes()
There was a problem hiding this comment.
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()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeCombinator::intersect()
instead please
There was a problem hiding this comment.
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']]); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntegerRangeType::fromInterval()
please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 09ae197
Thank you! |
closes phpstan/phpstan#7494