respect-validation/library/Rules/Finite.php

31 lines
582 B
PHP
Raw Normal View History

2015-08-20 05:35:43 +02:00
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
2015-08-20 05:35:43 +02:00
*/
declare(strict_types=1);
2015-08-20 05:35:43 +02:00
namespace Respect\Validation\Rules;
use function is_finite;
use function is_numeric;
2015-08-20 05:35:43 +02:00
/**
* Validates if the input is a finite number.
*
* @author Danilo Correa <danilosilva87@gmail.com>
2015-08-20 05:35:43 +02:00
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class Finite extends AbstractRule
2015-08-20 05:35:43 +02:00
{
/**
* {@inheritDoc}
2015-08-20 05:35:43 +02:00
*/
public function validate($input): bool
2015-08-20 05:35:43 +02:00
{
return is_numeric($input) && is_finite((float) $input);
2015-08-20 05:35:43 +02:00
}
}