- Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- Fatal error: Uncaught Error: Interface "ValidatorRuleInterface" not found in /in/3meF5:3
Stack trace:
#0 {main}
thrown in /in/3meF5 on line 3
Process exited with code 255.
<?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;
}
}
}