Only define filter_var options when it is valid

The third argument of "filter_var" must be either an integer or an
array. On PHP 8 this "FilterVar" rule fails because we always pass that
argument, even if it is null.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2020-10-04 11:04:45 +02:00
parent 2fad28b36b
commit e0c6f33c01
No known key found for this signature in database
GPG key ID: 221E9281655813A6

View file

@ -16,6 +16,8 @@ namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use function in_array;
use function is_array;
use function is_int;
use const FILTER_VALIDATE_BOOLEAN;
use const FILTER_VALIDATE_DOMAIN;
@ -57,6 +59,11 @@ final class FilterVar extends AbstractEnvelope
throw new ComponentException('Cannot accept the given filter');
}
parent::__construct(new Callback('filter_var', $filter, $options));
$arguments = [$filter];
if (is_array($options) || is_int($options)) {
$arguments[] = $options;
}
parent::__construct(new Callback('filter_var', ...$arguments));
}
}