$field_errors Field key → message. * @param list $notices Form-level notices. */ private function __construct( private readonly array $field_errors, private readonly array $notices, ) {} /** * Successful validation. * * @param list $notices Optional notices. */ public static function ok( array $notices = [] ): self { return new self( [], array_values( $notices ) ); } /** * Failed validation. * * @param array $field_errors Field errors. * @param list $notices Form-level notices. */ public static function invalid( array $field_errors, array $notices = [] ): self { return new self( $field_errors, array_values( $notices ) ); } /** * Whether validation passed. */ public function is_valid(): bool { return [] === $this->field_errors; } /** * Field errors keyed by field. * * @return array */ public function field_errors(): array { return $this->field_errors; } /** * Form-level notices. * * @return list */ public function notices(): array { return $this->notices; } }