function ValidationResult::__construct

Creates a ValidationResult object.

Parameters

int $severity: The severity of the result. Should be one of the SystemManager::REQUIREMENT_* constants. @todo Refactor this to use RequirementSeverity in https://www.drupal.org/i/3525121.

\Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] $messages: The result messages.

\Drupal\Core\StringTranslation\TranslatableMarkup|null $summary: A succinct summary of the result.

bool $assert_translatable: Whether to assert the messages are translatable. Internal use only.

Throws

\InvalidArgumentException Thrown if $messages is empty, or if it has 2 or more items but $summary is NULL.

File

core/modules/package_manager/src/ValidationResult.php, line 37

Class

ValidationResult
A value object to contain the results of a validation.

Namespace

Drupal\package_manager

Code

private function __construct(public readonly int $severity, private readonly array $messages, public readonly ?TranslatableMarkup $summary, bool $assert_translatable) {
  if ($assert_translatable) {
    assert(Inspector::assertAll(fn($message) => $message instanceof TranslatableMarkup, $messages));
  }
  if (empty($messages)) {
    throw new \InvalidArgumentException('At least one message is required.');
  }
  if (count($messages) > 1 && !$summary) {
    throw new \InvalidArgumentException('If more than one message is provided, a summary is required.');
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.