maxErrors = $max_errors; } /** * @return int */ public function maxErrors(): int { return $this->maxErrors; } /** * @param ValidationError $error * @return ErrorContainer */ public function add(ValidationError $error): self { $this->errors[] = $error; return $this; } /** * @return ValidationError[] */ public function all(): array { return $this->errors; } /** * @return ValidationError|null */ public function first(): ?ValidationError { if (!$this->errors) { return null; } return reset($this->errors); } /** * @return bool */ public function isFull(): bool { return count($this->errors) >= $this->maxErrors; } /** * @return bool */ public function isEmpty(): bool { return !$this->errors; } /** * @inheritDoc */ public function count(): int { return count($this->errors); } /** * @inheritDoc */ public function current(): ?ValidationError { return current($this->errors) ?: null; } /** * @inheritDoc */ #[\ReturnTypeWillChange] public function next(): ?ValidationError { return next($this->errors) ?: null; } /** * @inheritDoc */ public function key(): ?int { return key($this->errors); } /** * @inheritDoc */ public function valid(): bool { return key($this->errors) !== null; } /** * @inheritDoc */ #[\ReturnTypeWillChange] public function rewind(): ?ValidationError { return reset($this->errors) ?: null; } }