* SPDX-License-Identifier: MIT */ declare(strict_types=1); namespace Respect\Validation\Rules; use Attribute; use Respect\Validation\Message\Template; use Respect\Validation\Rules\Core\Simple; use function is_int; use function is_string; use function preg_match; #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] #[Template( '{{subject}} must be an integer value', '{{subject}} must not be an integer value', )] final class IntVal extends Simple { public function isValid(mixed $input): bool { if (is_int($input)) { return true; } if (!is_string($input)) { return false; } return preg_match('/^-?\d+$/', $input) === 1; } }