* * For the full copyright and license information, please view the LICENSE file * that was distributed with this source code. */ declare(strict_types=1); namespace Respect\Validation\Rules; use function floor; use function is_numeric; use function sqrt; /** * Validates whether the input is a perfect square. * * @author Danilo Benevides * @author Henrique Moody * @author Kleber Hamada Sato * @author Nick Lombard */ final class PerfectSquare extends AbstractRule { /** * {@inheritDoc} */ public function validate($input): bool { return is_numeric($input) && floor(sqrt((float) $input)) == sqrt((float) $input); } }