<?php class YearIsValid implements ValidatorRuleInterface { private string $errorText; private int $minYear; private int $maxYear; public function __construct(int $minYear, int $maxYear) { $this->minYear = $minYear; $this->maxYear = $maxYear; $this->errorText = "Год рождения не может быть меньше $this->minYear и не может быть больше $this->maxYear."; } public function __invoke(mixed $value): ?ValidationError { if (!is_int($value)) { throw new TypeException("Неправильный тип данных в аргументе функции."); } $resultMin = $value < $minYear; $resultMax = $value > $maxYear; if ($resultMin || $resultMax) { return new ValidationError($this->errorText); } else { return null; } } }
You have javascript disabled. You will not be able to edit any code.