mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
🐛 #1163 Fix handling for default option in filter_var
This commit is contained in:
parent
2d22db4cb7
commit
36f6930e0c
@ -625,10 +625,13 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
|
||||
if ($atomic_type instanceof Type\Atomic\ObjectLike) {
|
||||
$has_object_like = true;
|
||||
|
||||
if (isset($atomic_type->properties['default'])) {
|
||||
if (isset($atomic_type->properties['options'])
|
||||
&& $atomic_type->properties['options']->hasArray()
|
||||
&& isset($atomic_type->properties['options']->getTypes()['array']->properties['default'])
|
||||
) {
|
||||
$filter_type = Type::combineUnionTypes(
|
||||
$filter_type,
|
||||
$atomic_type->properties['default']
|
||||
$atomic_type->properties['options']->getTypes()['array']->properties['default']
|
||||
);
|
||||
} else {
|
||||
$filter_type->addType(new Type\Atomic\TFalse);
|
||||
|
@ -1217,10 +1217,10 @@ class FunctionCallTest extends TestCase
|
||||
return $filtered;
|
||||
}
|
||||
function filterNullableInt(string $s) : ?int {
|
||||
return filter_var($s, FILTER_VALIDATE_INT, ["default" => null]);
|
||||
return filter_var($s, FILTER_VALIDATE_INT, ["options" => ["default" => null]]);
|
||||
}
|
||||
function filterIntWithDefault(string $s) : int {
|
||||
return filter_var($s, FILTER_VALIDATE_INT, ["default" => 5]);
|
||||
return filter_var($s, FILTER_VALIDATE_INT, ["options" => ["default" => 5]]);
|
||||
}
|
||||
function filterBool(string $s) : bool {
|
||||
return filter_var($s, FILTER_VALIDATE_BOOLEAN);
|
||||
@ -1239,7 +1239,7 @@ class FunctionCallTest extends TestCase
|
||||
return $filtered;
|
||||
}
|
||||
function filterFloatWithDefault(string $s) : float {
|
||||
return filter_var($s, FILTER_VALIDATE_FLOAT, ["default" => 5.0]);
|
||||
return filter_var($s, FILTER_VALIDATE_FLOAT, ["options" => ["default" => 5.0]]);
|
||||
}',
|
||||
],
|
||||
'callVariableVar' => [
|
||||
|
Loading…
x
Reference in New Issue
Block a user