death-notifier/src/main/php/com/fwdekker/deathnotifier/validator/IsNotSetRule.php

30 lines
833 B
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
use com\fwdekker\deathnotifier\ValidationException;
/**
* Verifies that the input is not set.
*/
class IsNotSetRule extends Rule
{
/**
* Verifies that the input is not set.
*
* @param array<int|string, mixed> $inputs the list of inputs in which the value at `key` should be checked
* @param string $key the key in `inputs` of the input to check
* @return void if `$inputs[$key]` is not set
* @throws ValidationException if `$inputs[$key]` is set
*/
public function check(array $inputs, string $key): void
{
if (isset($inputs[$key]))
throw new ValidationException(
$this->override_message ?? "Field '" . htmlentities($key) . "' must not be set.",
$key
);
}
}