Skip to content

ValidationError

ValidationError stores an error message and the fields of an error.

class ValidationError implements ResetInterface

ImplementsResetInterface
Since1.0.0
SourceValidator/ValidationError.php

public function __construct(string $message, string $name, array<int, ValidationArgument|string> $arguments): mixed

Constructor

The arguments affected by this error.

ParameterTypeDescription
$messagestringThe message of this error.
$namestringThe name of the message.
$argumentsarray``<``int``, ValidationArgument`string>`

Returns mixed

MethodDescription
getArguments(): array<string, ValidationArgument>Retrieves the arguments which caused this error.
getFields(): array<int, string>Retrieves the fields which caused this error.
getIncident(): ?ValidationIncidentRetrieves the incident which caused this error.
getMessage(): stringRetrieves the message of this error.
getName(): stringRetrieves the name of this error.
hasArgument(ValidationArgument $argument): boolChecks if this error was caused for the given argument
hasField(string $fieldname): boolChecks if this error was caused for the given field
reset(): voidReturns the error to its initial state for reuse across requests.
setIncident(ValidationIncident $incident): voidSets the incident which caused this error.
setMessage(string $message): voidSets the message of this error.
setName(string $name): voidSets the name of this error.

public function getArguments(): array<string, ValidationArgument>

Retrieves the arguments which caused this error.

Returns array``<``string``, ValidationArgument> — An array of ValidationArgument.

public function getFields(): array<int, string>

Retrieves the fields which caused this error.

Returns array``<``int``, ``string``> — An array of field names.

public function getIncident(): ?ValidationIncident

Retrieves the incident which caused this error.

Returns ?ValidationIncident — The incident.

public function getMessage(): string

Retrieves the message of this error.

Returns string — The message.

public function getName(): string

Retrieves the name of this error.

Returns string — The error name.

public function hasArgument(ValidationArgument $argument): bool

Checks if this error was caused for the given argument

The argument.

ParameterTypeDescription
$argumentValidationArgumentThe argument.

Returns bool — The result.

public function hasField(string $fieldname): bool

Checks if this error was caused for the given field

The name of the field to check.

ParameterTypeDescription
$fieldnamestringThe name of the field to check.

Returns bool — The result.

public function reset(): void

Returns the error to its initial state for reuse across requests.

Drops the affected arguments, the message and the name, and detaches the error from the incident it belonged to, without touching that incident.

public function setIncident(ValidationIncident $incident): void

Sets the incident which caused this error.

The incident.

ParameterTypeDescription
$incidentValidationIncidentThe incident.

public function setMessage(string $message): void

Sets the message of this error.

The message.

ParameterTypeDescription
$messagestringThe message.

public function setName(string $name): void

Sets the name of this error.

The error name.

ParameterTypeDescription
$namestringThe error name.