mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
Bump respect/coding-standard from 4 to 5
This commit is contained in:
parent
7f66bcea10
commit
cfeb01e89e
355 changed files with 1579 additions and 1879 deletions
|
|
@ -38,10 +38,10 @@
|
|||
"phpunit/phpunit": "^12.5",
|
||||
"psr/http-message": "^1.0 || ^2.0",
|
||||
"ramsey/uuid": "^4",
|
||||
"respect/coding-standard": "^4.0",
|
||||
"respect/coding-standard": "^5.0",
|
||||
"sokil/php-isocodes": "^4.2.1",
|
||||
"sokil/php-isocodes-db-only": "^4.0",
|
||||
"squizlabs/php_codesniffer": "^3.8",
|
||||
"squizlabs/php_codesniffer": "^4.0",
|
||||
"symfony/var-exporter": "^6.4 || ^7.0"
|
||||
},
|
||||
"suggest": {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ final class InvalidRuleConstructorException extends ComponentException implement
|
|||
return implode(count($items) > 2 ? ', ' : ' ', $items);
|
||||
},
|
||||
$arguments,
|
||||
)
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ final class MissingComposerDependencyException extends ComponentException implem
|
|||
parent::__construct(sprintf(
|
||||
'%s. Run `composer require %s` to fix this issue.',
|
||||
$message,
|
||||
implode(' ', $dependencies)
|
||||
implode(' ', $dependencies),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ final class ValidationException extends InvalidArgumentException implements Exce
|
|||
{
|
||||
/**
|
||||
* @param array<string, mixed> $messages
|
||||
* @param array<string> $ignoredBacktracePaths
|
||||
* @param array<string> $ignoredBacktracePaths
|
||||
*/
|
||||
public function __construct(
|
||||
string $message,
|
||||
|
|
@ -28,6 +28,7 @@ final class ValidationException extends InvalidArgumentException implements Exce
|
|||
array $ignoredBacktracePaths = [],
|
||||
) {
|
||||
$this->overwriteFileAndLine($ignoredBacktracePaths);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,11 @@ use function ucfirst;
|
|||
|
||||
final class Factory
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
/** @var string[] */
|
||||
private array $rulesNamespaces = ['Respect\\Validation\\Rules'];
|
||||
|
||||
public function __construct(
|
||||
private readonly Transformer $transformer = new Prefix()
|
||||
private readonly Transformer $transformer = new Prefix(),
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -42,9 +40,7 @@ final class Factory
|
|||
return $clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $arguments
|
||||
*/
|
||||
/** @param mixed[] $arguments */
|
||||
public function rule(string $ruleName, array $arguments = []): Rule
|
||||
{
|
||||
return $this->createRuleSpec($this->transformer->transform(new RuleSpec($ruleName, $arguments)));
|
||||
|
|
@ -60,9 +56,7 @@ final class Factory
|
|||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $arguments
|
||||
*/
|
||||
/** @param mixed[] $arguments */
|
||||
private function createRule(string $ruleName, array $arguments = []): Rule
|
||||
{
|
||||
foreach ($this->rulesNamespaces as $namespace) {
|
||||
|
|
@ -72,7 +66,7 @@ final class Factory
|
|||
$reflection = new ReflectionClass($name);
|
||||
if (!$reflection->isSubclassOf(Rule::class)) {
|
||||
throw new InvalidClassException(
|
||||
sprintf('"%s" must be an instance of "%s"', $name, Rule::class)
|
||||
sprintf('"%s" must be an instance of "%s"', $name, Rule::class),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ trait CanValidateDateTime
|
|||
$formattedDate = DateTime::createFromFormat(
|
||||
$format,
|
||||
$value,
|
||||
new DateTimeZone(date_default_timezone_get())
|
||||
new DateTimeZone(date_default_timezone_get()),
|
||||
);
|
||||
|
||||
if ($formattedDate === false || $value !== $formattedDate->format($format)) {
|
||||
|
|
@ -48,9 +48,7 @@ trait CanValidateDateTime
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $info
|
||||
*/
|
||||
/** @param mixed[] $info */
|
||||
private function isDateTimeParsable(array $info): bool
|
||||
{
|
||||
return $info['error_count'] === 0 && $info['warning_count'] === 0;
|
||||
|
|
@ -61,9 +59,7 @@ trait CanValidateDateTime
|
|||
return preg_match('/[djSFmMnYy]/', $format) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $info
|
||||
*/
|
||||
/** @param mixed[] $info */
|
||||
private function isDateInformation(array $info): bool
|
||||
{
|
||||
if ($info['day']) {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,10 @@ use function mb_strtoupper;
|
|||
|
||||
final class DomainInfo
|
||||
{
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
private readonly array $data;
|
||||
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
private static array $runtimeCache = [];
|
||||
|
||||
public function __construct(string $tld)
|
||||
|
|
@ -36,9 +32,7 @@ final class DomainInfo
|
|||
$this->data = static::$runtimeCache[$tld];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
/** @return array<string> */
|
||||
public function getPublicSuffixes(): array
|
||||
{
|
||||
return $this->data;
|
||||
|
|
|
|||
|
|
@ -13,20 +13,16 @@ use Respect\Validation\Result;
|
|||
|
||||
interface Formatter
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $templates
|
||||
*/
|
||||
/** @param array<string, mixed> $templates */
|
||||
public function main(Result $result, array $templates, Translator $translator): string;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $templates
|
||||
*/
|
||||
/** @param array<string, mixed> $templates */
|
||||
public function full(
|
||||
Result $result,
|
||||
array $templates,
|
||||
Translator $translator,
|
||||
int $depth = 0,
|
||||
Result ...$siblings
|
||||
Result ...$siblings,
|
||||
): string;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ final readonly class Listed
|
|||
/** @param array<int, mixed> $values */
|
||||
public function __construct(
|
||||
public array $values,
|
||||
public string $lastGlue
|
||||
public string $lastGlue,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Respect\Validation\Message\Placeholder;
|
|||
final readonly class Quoted
|
||||
{
|
||||
public function __construct(
|
||||
private string $value
|
||||
private string $value,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@ use Respect\Validation\Result;
|
|||
|
||||
interface Renderer
|
||||
{
|
||||
public function render(Result $result, Translator $translator, ?string $template = null): string;
|
||||
public function render(Result $result, Translator $translator, string|null $template = null): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string|int, mixed> $templates
|
||||
*/
|
||||
/** @param array<string|int, mixed> $templates */
|
||||
public function main(Result $result, array $templates, Translator $translator): string
|
||||
{
|
||||
$selectedTemplates = $this->selectTemplates($result, $templates);
|
||||
|
|
@ -50,15 +48,13 @@ final readonly class StandardFormatter implements Formatter
|
|||
return $this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string|int, mixed> $templates
|
||||
*/
|
||||
/** @param array<string|int, mixed> $templates */
|
||||
public function full(
|
||||
Result $result,
|
||||
array $templates,
|
||||
Translator $translator,
|
||||
int $depth = 0,
|
||||
Result ...$siblings
|
||||
Result ...$siblings,
|
||||
): string {
|
||||
$selectedTemplates = $this->selectTemplates($result, $templates);
|
||||
$isFinalTemplate = $this->isFinalTemplate($result, $selectedTemplates);
|
||||
|
|
@ -71,7 +67,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
$indentation,
|
||||
$this->renderer->render(
|
||||
$this->getTemplated($depth > 0 ? $result->withDeepestPath() : $result, $selectedTemplates),
|
||||
$translator
|
||||
$translator,
|
||||
),
|
||||
);
|
||||
$depth++;
|
||||
|
|
@ -80,7 +76,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
if (!$isFinalTemplate) {
|
||||
$results = array_map(
|
||||
fn(Result $child) => $this->resultWithPath($result, $child),
|
||||
$this->extractDeduplicatedChildren($result)
|
||||
$this->extractDeduplicatedChildren($result),
|
||||
);
|
||||
foreach ($results as $child) {
|
||||
$rendered .= $this->full(
|
||||
|
|
@ -88,7 +84,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
$selectedTemplates,
|
||||
$translator,
|
||||
$depth,
|
||||
...array_filter($results, static fn (Result $sibling) => $sibling !== $child)
|
||||
...array_filter($results, static fn(Result $sibling) => $sibling !== $child),
|
||||
);
|
||||
$rendered .= PHP_EOL;
|
||||
}
|
||||
|
|
@ -110,7 +106,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
return [
|
||||
$result->getDeepestPath() ?? $result->id => $this->renderer->render(
|
||||
$this->getTemplated($result->withDeepestPath(), $selectedTemplates),
|
||||
$translator
|
||||
$translator,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
|
@ -121,7 +117,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
$messages[$key] = $this->array(
|
||||
$this->resultWithPath($result, $child),
|
||||
$this->selectTemplates($child, $selectedTemplates),
|
||||
$translator
|
||||
$translator,
|
||||
);
|
||||
if (count($messages[$key]) !== 1) {
|
||||
continue;
|
||||
|
|
@ -134,7 +130,7 @@ final readonly class StandardFormatter implements Formatter
|
|||
$self = [
|
||||
'__root__' => $this->renderer->render(
|
||||
$this->getTemplated($result->withDeepestPath(), $selectedTemplates),
|
||||
$translator
|
||||
$translator,
|
||||
),
|
||||
];
|
||||
|
||||
|
|
@ -169,10 +165,10 @@ final readonly class StandardFormatter implements Formatter
|
|||
|
||||
$childrenAlwaysVisible = array_filter(
|
||||
$result->children,
|
||||
fn (Result $child) => $this->isAlwaysVisible($child, ...array_filter(
|
||||
fn(Result $child) => $this->isAlwaysVisible($child, ...array_filter(
|
||||
$result->children,
|
||||
static fn (Result $sibling) => $sibling !== $child
|
||||
))
|
||||
static fn(Result $sibling) => $sibling !== $child,
|
||||
)),
|
||||
);
|
||||
if (count($childrenAlwaysVisible) !== 1) {
|
||||
return true;
|
||||
|
|
@ -184,11 +180,11 @@ final readonly class StandardFormatter implements Formatter
|
|||
|
||||
return array_reduce(
|
||||
$siblings,
|
||||
fn (bool $carry, Result $currentSibling) => $carry || $this->isAlwaysVisible(
|
||||
fn(bool $carry, Result $currentSibling) => $carry || $this->isAlwaysVisible(
|
||||
$currentSibling,
|
||||
...array_filter($siblings, static fn (Result $sibling) => $sibling !== $currentSibling)
|
||||
...array_filter($siblings, static fn(Result $sibling) => $sibling !== $currentSibling),
|
||||
),
|
||||
true
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -209,16 +205,14 @@ final readonly class StandardFormatter implements Formatter
|
|||
}
|
||||
|
||||
throw new ComponentException(
|
||||
sprintf('Template for "%s" must be a string, %s given', $key, stringify($templates[$key]))
|
||||
sprintf('Template for "%s" must be a string, %s given', $key, stringify($templates[$key])),
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string|int, mixed> $templates
|
||||
*/
|
||||
/** @param array<string|int, mixed> $templates */
|
||||
private function isFinalTemplate(Result $result, array $templates): bool
|
||||
{
|
||||
$keys = array_filter([$result->path, $result->name, $result->id], static fn($key) => $key !== null);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class StandardRenderer implements Renderer
|
|||
) {
|
||||
}
|
||||
|
||||
public function render(Result $result, Translator $translator, ?string $template = null): string
|
||||
public function render(Result $result, Translator $translator, string|null $template = null): string
|
||||
{
|
||||
$parameters = $result->parameters;
|
||||
$parameters['path'] = $result->path !== null ? Quoted::fromPath($result->path) : null;
|
||||
|
|
@ -51,7 +51,7 @@ final class StandardRenderer implements Renderer
|
|||
|
||||
return $this->placeholder($matches[1], $parameters[$matches[1]], $translator, $matches[3] ?? null);
|
||||
},
|
||||
$translator->translate($template ?? $this->getTemplateMessage($result))
|
||||
$translator->translate($template ?? $this->getTemplateMessage($result)),
|
||||
);
|
||||
|
||||
if (!$result->hasCustomTemplate() && $result->adjacent !== null) {
|
||||
|
|
@ -74,8 +74,12 @@ final class StandardRenderer implements Renderer
|
|||
return $this->templates[$rule::class] ?? [];
|
||||
}
|
||||
|
||||
private function placeholder(string $name, mixed $value, Translator $translator, ?string $modifier = null): string
|
||||
{
|
||||
private function placeholder(
|
||||
string $name,
|
||||
mixed $value,
|
||||
Translator $translator,
|
||||
string|null $modifier = null,
|
||||
): string {
|
||||
if ($modifier === 'quote' && is_string($value)) {
|
||||
return $this->placeholder($name, new Quoted($value), $translator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,15 +36,15 @@ use Respect\Validation\Message\Stringifier\QuotedStringifier;
|
|||
|
||||
final readonly class StandardStringifier implements Stringifier
|
||||
{
|
||||
private const MAXIMUM_DEPTH = 3;
|
||||
private const MAXIMUM_NUMBER_OF_ITEMS = 5;
|
||||
private const MAXIMUM_NUMBER_OF_PROPERTIES = self::MAXIMUM_NUMBER_OF_ITEMS;
|
||||
private const MAXIMUM_LENGTH = 120;
|
||||
private const int MAXIMUM_DEPTH = 3;
|
||||
private const int MAXIMUM_NUMBER_OF_ITEMS = 5;
|
||||
private const int MAXIMUM_NUMBER_OF_PROPERTIES = self::MAXIMUM_NUMBER_OF_ITEMS;
|
||||
private const int MAXIMUM_LENGTH = 120;
|
||||
|
||||
private Stringifier $stringifier;
|
||||
|
||||
public function __construct(
|
||||
private Quoter $quoter = new StandardQuoter(self::MAXIMUM_LENGTH)
|
||||
private Quoter $quoter = new StandardQuoter(self::MAXIMUM_LENGTH),
|
||||
) {
|
||||
$this->stringifier = $this->createStringifier($quoter);
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ final readonly class StandardStringifier implements Stringifier
|
|||
$stringifier,
|
||||
$quoter,
|
||||
self::MAXIMUM_DEPTH,
|
||||
self::MAXIMUM_NUMBER_OF_PROPERTIES
|
||||
self::MAXIMUM_NUMBER_OF_PROPERTIES,
|
||||
));
|
||||
$stringifier->prependStringifier(new EnumerationStringifier($quoter));
|
||||
$stringifier->prependStringifier(new ObjectWithDebugInfoStringifier($arrayStringifier, $quoter));
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ use function sprintf;
|
|||
final readonly class ListedStringifier implements Stringifier
|
||||
{
|
||||
public function __construct(
|
||||
private Stringifier $stringifier
|
||||
private Stringifier $stringifier,
|
||||
) {
|
||||
}
|
||||
|
||||
public function stringify(mixed $raw, int $depth): ?string
|
||||
public function stringify(mixed $raw, int $depth): string|null
|
||||
{
|
||||
if (!$raw instanceof Listed) {
|
||||
return null;
|
||||
|
|
@ -35,10 +35,11 @@ final readonly class ListedStringifier implements Stringifier
|
|||
return null;
|
||||
}
|
||||
|
||||
$strings = array_map(fn ($value) => $this->stringifier->stringify($value, $depth + 1), $raw->values);
|
||||
$strings = array_map(fn($value) => $this->stringifier->stringify($value, $depth + 1), $raw->values);
|
||||
if (count($strings) < 3) {
|
||||
return implode(sprintf(' %s ', $raw->lastGlue), $strings);
|
||||
}
|
||||
|
||||
$lastString = array_pop($strings);
|
||||
|
||||
return sprintf('%s, %s %s', implode(', ', $strings), $raw->lastGlue, $lastString);
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ use Respect\Validation\Message\Placeholder\Quoted;
|
|||
final readonly class QuotedStringifier implements Stringifier
|
||||
{
|
||||
public function __construct(
|
||||
private Quoter $quoter
|
||||
private Quoter $quoter,
|
||||
) {
|
||||
}
|
||||
|
||||
public function stringify(mixed $raw, int $depth): ?string
|
||||
public function stringify(mixed $raw, int $depth): string|null
|
||||
{
|
||||
if (!$raw instanceof Quoted) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ final readonly class ArrayTranslator implements Translator
|
|||
{
|
||||
/** @param array<string, string> $messages */
|
||||
public function __construct(
|
||||
private array $messages
|
||||
private array $messages,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,41 +75,33 @@ interface Builder extends
|
|||
|
||||
public static function contains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public static function containsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public static function control(string ...$additionalChars): Chain;
|
||||
|
||||
public static function countable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public static function countryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public static function cpf(): Chain;
|
||||
|
||||
public static function creditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public static function currencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public static function date(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public static function dateTime(?string $format = null): Chain;
|
||||
public static function dateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public static function dateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public static function decimal(int $decimals): Chain;
|
||||
|
|
@ -176,16 +168,14 @@ interface Builder extends
|
|||
|
||||
public static function infinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public static function instance(string $class): Chain;
|
||||
|
||||
public static function intType(): Chain;
|
||||
|
||||
public static function intVal(): Chain;
|
||||
|
||||
public static function ip(string $range = '*', ?int $options = null): Chain;
|
||||
public static function ip(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public static function isbn(): Chain;
|
||||
|
||||
|
|
@ -203,14 +193,10 @@ interface Builder extends
|
|||
|
||||
public static function keySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public static function languageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public static function lazy(callable $ruleCreator): Chain;
|
||||
|
||||
public static function leapDate(string $format): Chain;
|
||||
|
|
@ -281,7 +267,7 @@ interface Builder extends
|
|||
|
||||
public static function pesel(): Chain;
|
||||
|
||||
public static function phone(?string $countryCode = null): Chain;
|
||||
public static function phone(string|null $countryCode = null): Chain;
|
||||
|
||||
public static function phpLabel(): Chain;
|
||||
|
||||
|
|
@ -319,9 +305,7 @@ interface Builder extends
|
|||
|
||||
public static function scalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public static function size(string $unit, Rule $rule): Chain;
|
||||
|
||||
public static function slug(): Chain;
|
||||
|
|
@ -338,16 +322,12 @@ interface Builder extends
|
|||
|
||||
public static function subdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public static function subset(array $superset): Chain;
|
||||
|
||||
public static function symbolicLink(): Chain;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
/** @param array<string, mixed> $parameters */
|
||||
public static function templated(Rule $rule, string $template, array $parameters = []): Chain;
|
||||
|
||||
public static function time(string $format = 'H:i:s'): Chain;
|
||||
|
|
@ -366,15 +346,15 @@ interface Builder extends
|
|||
|
||||
public static function url(): Chain;
|
||||
|
||||
public static function uuid(?int $version = null): Chain;
|
||||
public static function uuid(int|null $version = null): Chain;
|
||||
|
||||
public static function version(): Chain;
|
||||
|
||||
public static function videoUrl(?string $service = null): Chain;
|
||||
public static function videoUrl(string|null $service = null): Chain;
|
||||
|
||||
public static function vowel(string ...$additionalChars): Chain;
|
||||
|
||||
public static function when(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public static function when(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public static function writable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ use DateTimeImmutable;
|
|||
use Respect\Validation\Rule;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
/**
|
||||
* @mixin Validator
|
||||
*/
|
||||
/** @mixin Validator */
|
||||
interface Chain extends
|
||||
Rule,
|
||||
KeyChain,
|
||||
|
|
@ -80,41 +78,33 @@ interface Chain extends
|
|||
|
||||
public function contains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public function containsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public function control(string ...$additionalChars): Chain;
|
||||
|
||||
public function countable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function countryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public function cpf(): Chain;
|
||||
|
||||
public function creditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function currencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public function date(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public function dateTime(?string $format = null): Chain;
|
||||
public function dateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function dateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public function decimal(int $decimals): Chain;
|
||||
|
|
@ -181,16 +171,14 @@ interface Chain extends
|
|||
|
||||
public function infinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public function instance(string $class): Chain;
|
||||
|
||||
public function intType(): Chain;
|
||||
|
||||
public function intVal(): Chain;
|
||||
|
||||
public function ip(string $range = '*', ?int $options = null): Chain;
|
||||
public function ip(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public function isbn(): Chain;
|
||||
|
||||
|
|
@ -208,14 +196,10 @@ interface Chain extends
|
|||
|
||||
public function keySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function languageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public function lazy(callable $ruleCreator): Chain;
|
||||
|
||||
public function leapDate(string $format): Chain;
|
||||
|
|
@ -286,7 +270,7 @@ interface Chain extends
|
|||
|
||||
public function pesel(): Chain;
|
||||
|
||||
public function phone(?string $countryCode = null): Chain;
|
||||
public function phone(string|null $countryCode = null): Chain;
|
||||
|
||||
public function phpLabel(): Chain;
|
||||
|
||||
|
|
@ -324,9 +308,7 @@ interface Chain extends
|
|||
|
||||
public function scalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function size(string $unit, Rule $rule): Chain;
|
||||
|
||||
public function slug(): Chain;
|
||||
|
|
@ -343,16 +325,12 @@ interface Chain extends
|
|||
|
||||
public function subdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public function subset(array $superset): Chain;
|
||||
|
||||
public function symbolicLink(): Chain;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
/** @param array<string, mixed> $parameters */
|
||||
public function templated(Rule $rule, string $template, array $parameters = []): Chain;
|
||||
|
||||
public function time(string $format = 'H:i:s'): Chain;
|
||||
|
|
@ -371,15 +349,15 @@ interface Chain extends
|
|||
|
||||
public function url(): Chain;
|
||||
|
||||
public function uuid(?int $version = null): Chain;
|
||||
public function uuid(int|null $version = null): Chain;
|
||||
|
||||
public function version(): Chain;
|
||||
|
||||
public function videoUrl(?string $service = null): Chain;
|
||||
public function videoUrl(string|null $service = null): Chain;
|
||||
|
||||
public function vowel(string ...$additionalChars): Chain;
|
||||
|
||||
public function when(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public function when(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public function writable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,42 +66,34 @@ interface KeyBuilder
|
|||
|
||||
public static function keyContains(int|string $key, mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public static function keyContainsAny(int|string $key, array $needles, bool $identical = false): Chain;
|
||||
|
||||
public static function keyControl(int|string $key, string ...$additionalChars): Chain;
|
||||
|
||||
public static function keyCountable(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public static function keyCountryCode(int|string $key, string $set = 'alpha-2'): Chain;
|
||||
|
||||
public static function keyCpf(int|string $key): Chain;
|
||||
|
||||
public static function keyCreditCard(int|string $key, string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public static function keyCurrencyCode(int|string $key, string $set = 'alpha-3'): Chain;
|
||||
|
||||
public static function keyDate(int|string $key, string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public static function keyDateTime(int|string $key, ?string $format = null): Chain;
|
||||
public static function keyDateTime(int|string $key, string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public static function keyDateTimeDiff(
|
||||
int|string $key,
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public static function keyDecimal(int|string $key, int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface KeyBuilder
|
|||
|
||||
public static function keyInfinite(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public static function keyInstance(int|string $key, string $class): Chain;
|
||||
|
||||
public static function keyIntType(int|string $key): Chain;
|
||||
|
||||
public static function keyIntVal(int|string $key): Chain;
|
||||
|
||||
public static function keyIp(int|string $key, string $range = '*', ?int $options = null): Chain;
|
||||
public static function keyIp(int|string $key, string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public static function keyIsbn(int|string $key): Chain;
|
||||
|
||||
|
|
@ -185,14 +175,10 @@ interface KeyBuilder
|
|||
|
||||
public static function keyJson(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public static function keyLanguageCode(int|string $key, string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public static function keyLazy(int|string $key, callable $ruleCreator): Chain;
|
||||
|
||||
public static function keyLeapDate(int|string $key, string $format): Chain;
|
||||
|
|
@ -259,7 +245,7 @@ interface KeyBuilder
|
|||
|
||||
public static function keyPesel(int|string $key): Chain;
|
||||
|
||||
public static function keyPhone(int|string $key, ?string $countryCode = null): Chain;
|
||||
public static function keyPhone(int|string $key, string|null $countryCode = null): Chain;
|
||||
|
||||
public static function keyPhpLabel(int|string $key): Chain;
|
||||
|
||||
|
|
@ -291,9 +277,7 @@ interface KeyBuilder
|
|||
|
||||
public static function keyScalarVal(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public static function keySize(int|string $key, string $unit, Rule $rule): Chain;
|
||||
|
||||
public static function keySlug(int|string $key): Chain;
|
||||
|
|
@ -310,9 +294,7 @@ interface KeyBuilder
|
|||
|
||||
public static function keySubdivisionCode(int|string $key, string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public static function keySubset(int|string $key, array $superset): Chain;
|
||||
|
||||
public static function keySymbolicLink(int|string $key): Chain;
|
||||
|
|
@ -331,15 +313,15 @@ interface KeyBuilder
|
|||
|
||||
public static function keyUrl(int|string $key): Chain;
|
||||
|
||||
public static function keyUuid(int|string $key, ?int $version = null): Chain;
|
||||
public static function keyUuid(int|string $key, int|null $version = null): Chain;
|
||||
|
||||
public static function keyVersion(int|string $key): Chain;
|
||||
|
||||
public static function keyVideoUrl(int|string $key, ?string $service = null): Chain;
|
||||
public static function keyVideoUrl(int|string $key, string|null $service = null): Chain;
|
||||
|
||||
public static function keyVowel(int|string $key, string ...$additionalChars): Chain;
|
||||
|
||||
public static function keyWhen(int|string $key, Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public static function keyWhen(int|string $key, Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public static function keyWritable(int|string $key): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,42 +66,34 @@ interface KeyChain
|
|||
|
||||
public function keyContains(int|string $key, mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public function keyContainsAny(int|string $key, array $needles, bool $identical = false): Chain;
|
||||
|
||||
public function keyControl(int|string $key, string ...$additionalChars): Chain;
|
||||
|
||||
public function keyCountable(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function keyCountryCode(int|string $key, string $set = 'alpha-2'): Chain;
|
||||
|
||||
public function keyCpf(int|string $key): Chain;
|
||||
|
||||
public function keyCreditCard(int|string $key, string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function keyCurrencyCode(int|string $key, string $set = 'alpha-3'): Chain;
|
||||
|
||||
public function keyDate(int|string $key, string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public function keyDateTime(int|string $key, ?string $format = null): Chain;
|
||||
public function keyDateTime(int|string $key, string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function keyDateTimeDiff(
|
||||
int|string $key,
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public function keyDecimal(int|string $key, int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface KeyChain
|
|||
|
||||
public function keyInfinite(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public function keyInstance(int|string $key, string $class): Chain;
|
||||
|
||||
public function keyIntType(int|string $key): Chain;
|
||||
|
||||
public function keyIntVal(int|string $key): Chain;
|
||||
|
||||
public function keyIp(int|string $key, string $range = '*', ?int $options = null): Chain;
|
||||
public function keyIp(int|string $key, string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public function keyIsbn(int|string $key): Chain;
|
||||
|
||||
|
|
@ -185,14 +175,10 @@ interface KeyChain
|
|||
|
||||
public function keyJson(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function keyLanguageCode(int|string $key, string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public function keyLazy(int|string $key, callable $ruleCreator): Chain;
|
||||
|
||||
public function keyLeapDate(int|string $key, string $format): Chain;
|
||||
|
|
@ -259,7 +245,7 @@ interface KeyChain
|
|||
|
||||
public function keyPesel(int|string $key): Chain;
|
||||
|
||||
public function keyPhone(int|string $key, ?string $countryCode = null): Chain;
|
||||
public function keyPhone(int|string $key, string|null $countryCode = null): Chain;
|
||||
|
||||
public function keyPhpLabel(int|string $key): Chain;
|
||||
|
||||
|
|
@ -291,9 +277,7 @@ interface KeyChain
|
|||
|
||||
public function keyScalarVal(int|string $key): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function keySize(int|string $key, string $unit, Rule $rule): Chain;
|
||||
|
||||
public function keySlug(int|string $key): Chain;
|
||||
|
|
@ -310,9 +294,7 @@ interface KeyChain
|
|||
|
||||
public function keySubdivisionCode(int|string $key, string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public function keySubset(int|string $key, array $superset): Chain;
|
||||
|
||||
public function keySymbolicLink(int|string $key): Chain;
|
||||
|
|
@ -331,15 +313,15 @@ interface KeyChain
|
|||
|
||||
public function keyUrl(int|string $key): Chain;
|
||||
|
||||
public function keyUuid(int|string $key, ?int $version = null): Chain;
|
||||
public function keyUuid(int|string $key, int|null $version = null): Chain;
|
||||
|
||||
public function keyVersion(int|string $key): Chain;
|
||||
|
||||
public function keyVideoUrl(int|string $key, ?string $service = null): Chain;
|
||||
public function keyVideoUrl(int|string $key, string|null $service = null): Chain;
|
||||
|
||||
public function keyVowel(int|string $key, string ...$additionalChars): Chain;
|
||||
|
||||
public function keyWhen(int|string $key, Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public function keyWhen(int|string $key, Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public function keyWritable(int|string $key): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,41 +65,33 @@ interface NotBuilder
|
|||
|
||||
public static function notContains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public static function notContainsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public static function notControl(string ...$additionalChars): Chain;
|
||||
|
||||
public static function notCountable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public static function notCountryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public static function notCpf(): Chain;
|
||||
|
||||
public static function notCreditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public static function notCurrencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public static function notDate(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public static function notDateTime(?string $format = null): Chain;
|
||||
public static function notDateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public static function notDateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public static function notDecimal(int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface NotBuilder
|
|||
|
||||
public static function notInfinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public static function notInstance(string $class): Chain;
|
||||
|
||||
public static function notIntType(): Chain;
|
||||
|
||||
public static function notIntVal(): Chain;
|
||||
|
||||
public static function notIp(string $range = '*', ?int $options = null): Chain;
|
||||
public static function notIp(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public static function notIsbn(): Chain;
|
||||
|
||||
|
|
@ -193,14 +183,10 @@ interface NotBuilder
|
|||
|
||||
public static function notKeySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public static function notLanguageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public static function notLazy(callable $ruleCreator): Chain;
|
||||
|
||||
public static function notLeapDate(string $format): Chain;
|
||||
|
|
@ -257,7 +243,7 @@ interface NotBuilder
|
|||
|
||||
public static function notPesel(): Chain;
|
||||
|
||||
public static function notPhone(?string $countryCode = null): Chain;
|
||||
public static function notPhone(string|null $countryCode = null): Chain;
|
||||
|
||||
public static function notPhpLabel(): Chain;
|
||||
|
||||
|
|
@ -295,9 +281,7 @@ interface NotBuilder
|
|||
|
||||
public static function notScalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public static function notSize(string $unit, Rule $rule): Chain;
|
||||
|
||||
public static function notSlug(): Chain;
|
||||
|
|
@ -314,9 +298,7 @@ interface NotBuilder
|
|||
|
||||
public static function notSubdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public static function notSubset(array $superset): Chain;
|
||||
|
||||
public static function notSymbolicLink(): Chain;
|
||||
|
|
@ -335,15 +317,15 @@ interface NotBuilder
|
|||
|
||||
public static function notUrl(): Chain;
|
||||
|
||||
public static function notUuid(?int $version = null): Chain;
|
||||
public static function notUuid(int|null $version = null): Chain;
|
||||
|
||||
public static function notVersion(): Chain;
|
||||
|
||||
public static function notVideoUrl(?string $service = null): Chain;
|
||||
public static function notVideoUrl(string|null $service = null): Chain;
|
||||
|
||||
public static function notVowel(string ...$additionalChars): Chain;
|
||||
|
||||
public static function notWhen(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public static function notWhen(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public static function notWritable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,41 +65,33 @@ interface NotChain
|
|||
|
||||
public function notContains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public function notContainsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public function notControl(string ...$additionalChars): Chain;
|
||||
|
||||
public function notCountable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function notCountryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public function notCpf(): Chain;
|
||||
|
||||
public function notCreditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function notCurrencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public function notDate(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public function notDateTime(?string $format = null): Chain;
|
||||
public function notDateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function notDateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public function notDecimal(int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface NotChain
|
|||
|
||||
public function notInfinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public function notInstance(string $class): Chain;
|
||||
|
||||
public function notIntType(): Chain;
|
||||
|
||||
public function notIntVal(): Chain;
|
||||
|
||||
public function notIp(string $range = '*', ?int $options = null): Chain;
|
||||
public function notIp(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public function notIsbn(): Chain;
|
||||
|
||||
|
|
@ -193,14 +183,10 @@ interface NotChain
|
|||
|
||||
public function notKeySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function notLanguageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public function notLazy(callable $ruleCreator): Chain;
|
||||
|
||||
public function notLeapDate(string $format): Chain;
|
||||
|
|
@ -257,7 +243,7 @@ interface NotChain
|
|||
|
||||
public function notPesel(): Chain;
|
||||
|
||||
public function notPhone(?string $countryCode = null): Chain;
|
||||
public function notPhone(string|null $countryCode = null): Chain;
|
||||
|
||||
public function notPhpLabel(): Chain;
|
||||
|
||||
|
|
@ -295,9 +281,7 @@ interface NotChain
|
|||
|
||||
public function notScalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function notSize(string $unit, Rule $rule): Chain;
|
||||
|
||||
public function notSlug(): Chain;
|
||||
|
|
@ -314,9 +298,7 @@ interface NotChain
|
|||
|
||||
public function notSubdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public function notSubset(array $superset): Chain;
|
||||
|
||||
public function notSymbolicLink(): Chain;
|
||||
|
|
@ -335,15 +317,15 @@ interface NotChain
|
|||
|
||||
public function notUrl(): Chain;
|
||||
|
||||
public function notUuid(?int $version = null): Chain;
|
||||
public function notUuid(int|null $version = null): Chain;
|
||||
|
||||
public function notVersion(): Chain;
|
||||
|
||||
public function notVideoUrl(?string $service = null): Chain;
|
||||
public function notVideoUrl(string|null $service = null): Chain;
|
||||
|
||||
public function notVowel(string ...$additionalChars): Chain;
|
||||
|
||||
public function notWhen(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public function notWhen(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public function notWritable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,41 +67,33 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrContains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public static function nullOrContainsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public static function nullOrControl(string ...$additionalChars): Chain;
|
||||
|
||||
public static function nullOrCountable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public static function nullOrCountryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public static function nullOrCpf(): Chain;
|
||||
|
||||
public static function nullOrCreditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public static function nullOrCurrencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public static function nullOrDate(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public static function nullOrDateTime(?string $format = null): Chain;
|
||||
public static function nullOrDateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public static function nullOrDateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public static function nullOrDecimal(int $decimals): Chain;
|
||||
|
|
@ -168,16 +160,14 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrInfinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public static function nullOrInstance(string $class): Chain;
|
||||
|
||||
public static function nullOrIntType(): Chain;
|
||||
|
||||
public static function nullOrIntVal(): Chain;
|
||||
|
||||
public static function nullOrIp(string $range = '*', ?int $options = null): Chain;
|
||||
public static function nullOrIp(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public static function nullOrIsbn(): Chain;
|
||||
|
||||
|
|
@ -195,14 +185,10 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrKeySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public static function nullOrLanguageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public static function nullOrLazy(callable $ruleCreator): Chain;
|
||||
|
||||
public static function nullOrLeapDate(string $format): Chain;
|
||||
|
|
@ -267,7 +253,7 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrPesel(): Chain;
|
||||
|
||||
public static function nullOrPhone(?string $countryCode = null): Chain;
|
||||
public static function nullOrPhone(string|null $countryCode = null): Chain;
|
||||
|
||||
public static function nullOrPhpLabel(): Chain;
|
||||
|
||||
|
|
@ -305,9 +291,7 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrScalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public static function nullOrSize(string $unit, Rule $rule): Chain;
|
||||
|
||||
public static function nullOrSlug(): Chain;
|
||||
|
|
@ -324,9 +308,7 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrSubdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public static function nullOrSubset(array $superset): Chain;
|
||||
|
||||
public static function nullOrSymbolicLink(): Chain;
|
||||
|
|
@ -345,15 +327,15 @@ interface NullOrBuilder
|
|||
|
||||
public static function nullOrUrl(): Chain;
|
||||
|
||||
public static function nullOrUuid(?int $version = null): Chain;
|
||||
public static function nullOrUuid(int|null $version = null): Chain;
|
||||
|
||||
public static function nullOrVersion(): Chain;
|
||||
|
||||
public static function nullOrVideoUrl(?string $service = null): Chain;
|
||||
public static function nullOrVideoUrl(string|null $service = null): Chain;
|
||||
|
||||
public static function nullOrVowel(string ...$additionalChars): Chain;
|
||||
|
||||
public static function nullOrWhen(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public static function nullOrWhen(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public static function nullOrWritable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,41 +67,33 @@ interface NullOrChain
|
|||
|
||||
public function nullOrContains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public function nullOrContainsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public function nullOrControl(string ...$additionalChars): Chain;
|
||||
|
||||
public function nullOrCountable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function nullOrCountryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public function nullOrCpf(): Chain;
|
||||
|
||||
public function nullOrCreditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function nullOrCurrencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public function nullOrDate(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public function nullOrDateTime(?string $format = null): Chain;
|
||||
public function nullOrDateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function nullOrDateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public function nullOrDecimal(int $decimals): Chain;
|
||||
|
|
@ -168,16 +160,14 @@ interface NullOrChain
|
|||
|
||||
public function nullOrInfinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public function nullOrInstance(string $class): Chain;
|
||||
|
||||
public function nullOrIntType(): Chain;
|
||||
|
||||
public function nullOrIntVal(): Chain;
|
||||
|
||||
public function nullOrIp(string $range = '*', ?int $options = null): Chain;
|
||||
public function nullOrIp(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public function nullOrIsbn(): Chain;
|
||||
|
||||
|
|
@ -195,14 +185,10 @@ interface NullOrChain
|
|||
|
||||
public function nullOrKeySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function nullOrLanguageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public function nullOrLazy(callable $ruleCreator): Chain;
|
||||
|
||||
public function nullOrLeapDate(string $format): Chain;
|
||||
|
|
@ -267,7 +253,7 @@ interface NullOrChain
|
|||
|
||||
public function nullOrPesel(): Chain;
|
||||
|
||||
public function nullOrPhone(?string $countryCode = null): Chain;
|
||||
public function nullOrPhone(string|null $countryCode = null): Chain;
|
||||
|
||||
public function nullOrPhpLabel(): Chain;
|
||||
|
||||
|
|
@ -305,9 +291,7 @@ interface NullOrChain
|
|||
|
||||
public function nullOrScalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function nullOrSize(string $unit, Rule $rule): Chain;
|
||||
|
||||
public function nullOrSlug(): Chain;
|
||||
|
|
@ -324,9 +308,7 @@ interface NullOrChain
|
|||
|
||||
public function nullOrSubdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public function nullOrSubset(array $superset): Chain;
|
||||
|
||||
public function nullOrSymbolicLink(): Chain;
|
||||
|
|
@ -345,15 +327,15 @@ interface NullOrChain
|
|||
|
||||
public function nullOrUrl(): Chain;
|
||||
|
||||
public function nullOrUuid(?int $version = null): Chain;
|
||||
public function nullOrUuid(int|null $version = null): Chain;
|
||||
|
||||
public function nullOrVersion(): Chain;
|
||||
|
||||
public function nullOrVideoUrl(?string $service = null): Chain;
|
||||
public function nullOrVideoUrl(string|null $service = null): Chain;
|
||||
|
||||
public function nullOrVowel(string ...$additionalChars): Chain;
|
||||
|
||||
public function nullOrWhen(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public function nullOrWhen(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public function nullOrWritable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -70,42 +70,34 @@ interface PropertyBuilder
|
|||
bool $identical = false,
|
||||
): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public static function propertyContainsAny(string $propertyName, array $needles, bool $identical = false): Chain;
|
||||
|
||||
public static function propertyControl(string $propertyName, string ...$additionalChars): Chain;
|
||||
|
||||
public static function propertyCountable(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public static function propertyCountryCode(string $propertyName, string $set = 'alpha-2'): Chain;
|
||||
|
||||
public static function propertyCpf(string $propertyName): Chain;
|
||||
|
||||
public static function propertyCreditCard(string $propertyName, string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public static function propertyCurrencyCode(string $propertyName, string $set = 'alpha-3'): Chain;
|
||||
|
||||
public static function propertyDate(string $propertyName, string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public static function propertyDateTime(string $propertyName, ?string $format = null): Chain;
|
||||
public static function propertyDateTime(string $propertyName, string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public static function propertyDateTimeDiff(
|
||||
string $propertyName,
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public static function propertyDecimal(string $propertyName, int $decimals): Chain;
|
||||
|
|
@ -170,16 +162,14 @@ interface PropertyBuilder
|
|||
|
||||
public static function propertyInfinite(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public static function propertyInstance(string $propertyName, string $class): Chain;
|
||||
|
||||
public static function propertyIntType(string $propertyName): Chain;
|
||||
|
||||
public static function propertyIntVal(string $propertyName): Chain;
|
||||
|
||||
public static function propertyIp(string $propertyName, string $range = '*', ?int $options = null): Chain;
|
||||
public static function propertyIp(string $propertyName, string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public static function propertyIsbn(string $propertyName): Chain;
|
||||
|
||||
|
|
@ -189,14 +179,10 @@ interface PropertyBuilder
|
|||
|
||||
public static function propertyJson(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public static function propertyLanguageCode(string $propertyName, string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public static function propertyLazy(string $propertyName, callable $ruleCreator): Chain;
|
||||
|
||||
public static function propertyLeapDate(string $propertyName, string $format): Chain;
|
||||
|
|
@ -263,7 +249,7 @@ interface PropertyBuilder
|
|||
|
||||
public static function propertyPesel(string $propertyName): Chain;
|
||||
|
||||
public static function propertyPhone(string $propertyName, ?string $countryCode = null): Chain;
|
||||
public static function propertyPhone(string $propertyName, string|null $countryCode = null): Chain;
|
||||
|
||||
public static function propertyPhpLabel(string $propertyName): Chain;
|
||||
|
||||
|
|
@ -299,9 +285,7 @@ interface PropertyBuilder
|
|||
|
||||
public static function propertyScalarVal(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public static function propertySize(string $propertyName, string $unit, Rule $rule): Chain;
|
||||
|
||||
public static function propertySlug(string $propertyName): Chain;
|
||||
|
|
@ -318,9 +302,7 @@ interface PropertyBuilder
|
|||
|
||||
public static function propertySubdivisionCode(string $propertyName, string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public static function propertySubset(string $propertyName, array $superset): Chain;
|
||||
|
||||
public static function propertySymbolicLink(string $propertyName): Chain;
|
||||
|
|
@ -339,15 +321,15 @@ interface PropertyBuilder
|
|||
|
||||
public static function propertyUrl(string $propertyName): Chain;
|
||||
|
||||
public static function propertyUuid(string $propertyName, ?int $version = null): Chain;
|
||||
public static function propertyUuid(string $propertyName, int|null $version = null): Chain;
|
||||
|
||||
public static function propertyVersion(string $propertyName): Chain;
|
||||
|
||||
public static function propertyVideoUrl(string $propertyName, ?string $service = null): Chain;
|
||||
public static function propertyVideoUrl(string $propertyName, string|null $service = null): Chain;
|
||||
|
||||
public static function propertyVowel(string $propertyName, string ...$additionalChars): Chain;
|
||||
|
||||
public static function propertyWhen(string $propertyName, Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public static function propertyWhen(string $propertyName, Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public static function propertyWritable(string $propertyName): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,42 +66,34 @@ interface PropertyChain
|
|||
|
||||
public function propertyContains(string $propertyName, mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public function propertyContainsAny(string $propertyName, array $needles, bool $identical = false): Chain;
|
||||
|
||||
public function propertyControl(string $propertyName, string ...$additionalChars): Chain;
|
||||
|
||||
public function propertyCountable(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function propertyCountryCode(string $propertyName, string $set = 'alpha-2'): Chain;
|
||||
|
||||
public function propertyCpf(string $propertyName): Chain;
|
||||
|
||||
public function propertyCreditCard(string $propertyName, string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function propertyCurrencyCode(string $propertyName, string $set = 'alpha-3'): Chain;
|
||||
|
||||
public function propertyDate(string $propertyName, string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public function propertyDateTime(string $propertyName, ?string $format = null): Chain;
|
||||
public function propertyDateTime(string $propertyName, string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function propertyDateTimeDiff(
|
||||
string $propertyName,
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public function propertyDecimal(string $propertyName, int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface PropertyChain
|
|||
|
||||
public function propertyInfinite(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public function propertyInstance(string $propertyName, string $class): Chain;
|
||||
|
||||
public function propertyIntType(string $propertyName): Chain;
|
||||
|
||||
public function propertyIntVal(string $propertyName): Chain;
|
||||
|
||||
public function propertyIp(string $propertyName, string $range = '*', ?int $options = null): Chain;
|
||||
public function propertyIp(string $propertyName, string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public function propertyIsbn(string $propertyName): Chain;
|
||||
|
||||
|
|
@ -185,14 +175,10 @@ interface PropertyChain
|
|||
|
||||
public function propertyJson(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function propertyLanguageCode(string $propertyName, string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public function propertyLazy(string $propertyName, callable $ruleCreator): Chain;
|
||||
|
||||
public function propertyLeapDate(string $propertyName, string $format): Chain;
|
||||
|
|
@ -259,7 +245,7 @@ interface PropertyChain
|
|||
|
||||
public function propertyPesel(string $propertyName): Chain;
|
||||
|
||||
public function propertyPhone(string $propertyName, ?string $countryCode = null): Chain;
|
||||
public function propertyPhone(string $propertyName, string|null $countryCode = null): Chain;
|
||||
|
||||
public function propertyPhpLabel(string $propertyName): Chain;
|
||||
|
||||
|
|
@ -291,9 +277,7 @@ interface PropertyChain
|
|||
|
||||
public function propertyScalarVal(string $propertyName): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function propertySize(string $propertyName, string $unit, Rule $rule): Chain;
|
||||
|
||||
public function propertySlug(string $propertyName): Chain;
|
||||
|
|
@ -310,9 +294,7 @@ interface PropertyChain
|
|||
|
||||
public function propertySubdivisionCode(string $propertyName, string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public function propertySubset(string $propertyName, array $superset): Chain;
|
||||
|
||||
public function propertySymbolicLink(string $propertyName): Chain;
|
||||
|
|
@ -331,15 +313,15 @@ interface PropertyChain
|
|||
|
||||
public function propertyUrl(string $propertyName): Chain;
|
||||
|
||||
public function propertyUuid(string $propertyName, ?int $version = null): Chain;
|
||||
public function propertyUuid(string $propertyName, int|null $version = null): Chain;
|
||||
|
||||
public function propertyVersion(string $propertyName): Chain;
|
||||
|
||||
public function propertyVideoUrl(string $propertyName, ?string $service = null): Chain;
|
||||
public function propertyVideoUrl(string $propertyName, string|null $service = null): Chain;
|
||||
|
||||
public function propertyVowel(string $propertyName, string ...$additionalChars): Chain;
|
||||
|
||||
public function propertyWhen(string $propertyName, Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public function propertyWhen(string $propertyName, Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public function propertyWritable(string $propertyName): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,41 +65,33 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrContains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public static function undefOrContainsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public static function undefOrControl(string ...$additionalChars): Chain;
|
||||
|
||||
public static function undefOrCountable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public static function undefOrCountryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public static function undefOrCpf(): Chain;
|
||||
|
||||
public static function undefOrCreditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public static function undefOrCurrencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public static function undefOrDate(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public static function undefOrDateTime(?string $format = null): Chain;
|
||||
public static function undefOrDateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public static function undefOrDateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public static function undefOrDecimal(int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrInfinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public static function undefOrInstance(string $class): Chain;
|
||||
|
||||
public static function undefOrIntType(): Chain;
|
||||
|
||||
public static function undefOrIntVal(): Chain;
|
||||
|
||||
public static function undefOrIp(string $range = '*', ?int $options = null): Chain;
|
||||
public static function undefOrIp(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public static function undefOrIsbn(): Chain;
|
||||
|
||||
|
|
@ -193,14 +183,10 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrKeySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public static function undefOrLanguageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public static function undefOrLazy(callable $ruleCreator): Chain;
|
||||
|
||||
public static function undefOrLeapDate(string $format): Chain;
|
||||
|
|
@ -265,7 +251,7 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrPesel(): Chain;
|
||||
|
||||
public static function undefOrPhone(?string $countryCode = null): Chain;
|
||||
public static function undefOrPhone(string|null $countryCode = null): Chain;
|
||||
|
||||
public static function undefOrPhpLabel(): Chain;
|
||||
|
||||
|
|
@ -303,9 +289,7 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrScalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public static function undefOrSize(string $unit, Rule $rule): Chain;
|
||||
|
||||
public static function undefOrSlug(): Chain;
|
||||
|
|
@ -322,9 +306,7 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrSubdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public static function undefOrSubset(array $superset): Chain;
|
||||
|
||||
public static function undefOrSymbolicLink(): Chain;
|
||||
|
|
@ -343,15 +325,15 @@ interface UndefOrBuilder
|
|||
|
||||
public static function undefOrUrl(): Chain;
|
||||
|
||||
public static function undefOrUuid(?int $version = null): Chain;
|
||||
public static function undefOrUuid(int|null $version = null): Chain;
|
||||
|
||||
public static function undefOrVersion(): Chain;
|
||||
|
||||
public static function undefOrVideoUrl(?string $service = null): Chain;
|
||||
public static function undefOrVideoUrl(string|null $service = null): Chain;
|
||||
|
||||
public static function undefOrVowel(string ...$additionalChars): Chain;
|
||||
|
||||
public static function undefOrWhen(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public static function undefOrWhen(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public static function undefOrWritable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,41 +65,33 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrContains(mixed $containsValue, bool $identical = false): Chain;
|
||||
|
||||
/**
|
||||
* @param non-empty-array<mixed> $needles
|
||||
*/
|
||||
/** @param non-empty-array<mixed> $needles */
|
||||
public function undefOrContainsAny(array $needles, bool $identical = false): Chain;
|
||||
|
||||
public function undefOrControl(string ...$additionalChars): Chain;
|
||||
|
||||
public function undefOrCountable(): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function undefOrCountryCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
public function undefOrCpf(): Chain;
|
||||
|
||||
public function undefOrCreditCard(string $brand = 'Any'): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-3"|"numeric" $set
|
||||
*/
|
||||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function undefOrCurrencyCode(string $set = 'alpha-3'): Chain;
|
||||
|
||||
public function undefOrDate(string $format = 'Y-m-d'): Chain;
|
||||
|
||||
public function undefOrDateTime(?string $format = null): Chain;
|
||||
public function undefOrDateTime(string|null $format = null): Chain;
|
||||
|
||||
/**
|
||||
* @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type
|
||||
*/
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function undefOrDateTimeDiff(
|
||||
string $type,
|
||||
Rule $rule,
|
||||
?string $format = null,
|
||||
?DateTimeImmutable $now = null,
|
||||
string|null $format = null,
|
||||
DateTimeImmutable|null $now = null,
|
||||
): Chain;
|
||||
|
||||
public function undefOrDecimal(int $decimals): Chain;
|
||||
|
|
@ -166,16 +158,14 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrInfinite(): Chain;
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
/** @param class-string $class */
|
||||
public function undefOrInstance(string $class): Chain;
|
||||
|
||||
public function undefOrIntType(): Chain;
|
||||
|
||||
public function undefOrIntVal(): Chain;
|
||||
|
||||
public function undefOrIp(string $range = '*', ?int $options = null): Chain;
|
||||
public function undefOrIp(string $range = '*', int|null $options = null): Chain;
|
||||
|
||||
public function undefOrIsbn(): Chain;
|
||||
|
||||
|
|
@ -193,14 +183,10 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrKeySet(Rule $rule, Rule ...$rules): Chain;
|
||||
|
||||
/**
|
||||
* @param "alpha-2"|"alpha-3" $set
|
||||
*/
|
||||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function undefOrLanguageCode(string $set = 'alpha-2'): Chain;
|
||||
|
||||
/**
|
||||
* @param callable(mixed): Rule $ruleCreator
|
||||
*/
|
||||
/** @param callable(mixed): Rule $ruleCreator */
|
||||
public function undefOrLazy(callable $ruleCreator): Chain;
|
||||
|
||||
public function undefOrLeapDate(string $format): Chain;
|
||||
|
|
@ -265,7 +251,7 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrPesel(): Chain;
|
||||
|
||||
public function undefOrPhone(?string $countryCode = null): Chain;
|
||||
public function undefOrPhone(string|null $countryCode = null): Chain;
|
||||
|
||||
public function undefOrPhpLabel(): Chain;
|
||||
|
||||
|
|
@ -303,9 +289,7 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrScalarVal(): Chain;
|
||||
|
||||
/**
|
||||
* @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit
|
||||
*/
|
||||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function undefOrSize(string $unit, Rule $rule): Chain;
|
||||
|
||||
public function undefOrSlug(): Chain;
|
||||
|
|
@ -322,9 +306,7 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrSubdivisionCode(string $countryCode): Chain;
|
||||
|
||||
/**
|
||||
* @param mixed[] $superset
|
||||
*/
|
||||
/** @param mixed[] $superset */
|
||||
public function undefOrSubset(array $superset): Chain;
|
||||
|
||||
public function undefOrSymbolicLink(): Chain;
|
||||
|
|
@ -343,15 +325,15 @@ interface UndefOrChain
|
|||
|
||||
public function undefOrUrl(): Chain;
|
||||
|
||||
public function undefOrUuid(?int $version = null): Chain;
|
||||
public function undefOrUuid(int|null $version = null): Chain;
|
||||
|
||||
public function undefOrVersion(): Chain;
|
||||
|
||||
public function undefOrVideoUrl(?string $service = null): Chain;
|
||||
public function undefOrVideoUrl(string|null $service = null): Chain;
|
||||
|
||||
public function undefOrVowel(string ...$additionalChars): Chain;
|
||||
|
||||
public function undefOrWhen(Rule $when, Rule $then, ?Rule $else = null): Chain;
|
||||
public function undefOrWhen(Rule $when, Rule $then, Rule|null $else = null): Chain;
|
||||
|
||||
public function undefOrWritable(): Chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Respect\Validation;
|
|||
|
||||
interface Rule
|
||||
{
|
||||
public const TEMPLATE_STANDARD = '__standard__';
|
||||
public const string TEMPLATE_STANDARD = '__standard__';
|
||||
|
||||
public function evaluate(mixed $input): Result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ use function count;
|
|||
)]
|
||||
final class AllOf extends Composite
|
||||
{
|
||||
public const TEMPLATE_ALL = '__all__';
|
||||
public const TEMPLATE_SOME = '__some__';
|
||||
public const string TEMPLATE_ALL = '__all__';
|
||||
public const string TEMPLATE_SOME = '__some__';
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry && $result->hasPassed, true);
|
||||
$failed = array_filter($children, static fn (Result $result): bool => !$result->hasPassed);
|
||||
$children = array_map(static fn(Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce($children, static fn(bool $carry, Result $result) => $carry && $result->hasPassed, true);
|
||||
$failed = array_filter($children, static fn(Result $result): bool => !$result->hasPassed);
|
||||
$template = self::TEMPLATE_SOME;
|
||||
if (count($children) === count($failed)) {
|
||||
$template = self::TEMPLATE_ALL;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use Respect\Validation\Rules\Core\Simple;
|
|||
)]
|
||||
final class AlwaysInvalid extends Simple
|
||||
{
|
||||
public const TEMPLATE_SIMPLE = '__simple__';
|
||||
public const string TEMPLATE_SIMPLE = '__simple__';
|
||||
|
||||
public function isValid(mixed $input): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ final class AnyOf extends Composite
|
|||
{
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$children = array_map(static fn(Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce(
|
||||
$children,
|
||||
static fn (bool $carry, Result $result) => $carry || $result->hasPassed,
|
||||
static fn(bool $carry, Result $result) => $carry || $result->hasPassed,
|
||||
false,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ final class Attributes implements Rule
|
|||
foreach ($reflection->getAttributes(Rule::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
|
||||
$rules[] = $attribute->newInstance();
|
||||
}
|
||||
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
$childrenRules = [];
|
||||
foreach ($property->getAttributes(Rule::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ final readonly class Base implements Rule
|
|||
{
|
||||
public function __construct(
|
||||
private int $base,
|
||||
private string $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
private string $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
) {
|
||||
$max = mb_strlen($this->chars);
|
||||
if ($base > $max) {
|
||||
|
|
@ -42,7 +42,7 @@ final readonly class Base implements Rule
|
|||
(bool) preg_match('@^[' . mb_substr($this->chars, 0, $this->base) . ']+$@', (string) $input),
|
||||
$input,
|
||||
$this,
|
||||
['base' => $this->base]
|
||||
['base' => $this->base],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,12 +33,12 @@ final class Between extends Envelope
|
|||
parent::__construct(
|
||||
new AllOf(
|
||||
new GreaterThanOrEqual($minValue),
|
||||
new LessThanOrEqual($maxValue)
|
||||
new LessThanOrEqual($maxValue),
|
||||
),
|
||||
[
|
||||
'minValue' => $minValue,
|
||||
'maxValue' => $maxValue,
|
||||
]
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ final class BetweenExclusive extends Envelope
|
|||
|
||||
parent::__construct(
|
||||
new AllOf(new GreaterThan($minimum), new LessThan($maximum)),
|
||||
['minValue' => $minimum, 'maxValue' => $maximum]
|
||||
['minValue' => $minimum, 'maxValue' => $maximum],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ use function is_scalar;
|
|||
use function mb_strlen;
|
||||
use function strval;
|
||||
|
||||
/**
|
||||
* @see https://nl.wikipedia.org/wiki/Burgerservicenummer
|
||||
*/
|
||||
/** @see https://nl.wikipedia.org/wiki/Burgerservicenummer */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid BSN',
|
||||
|
|
|
|||
|
|
@ -27,21 +27,19 @@ use function set_error_handler;
|
|||
)]
|
||||
final class Call implements Rule
|
||||
{
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
/** @var callable */
|
||||
private $callable;
|
||||
|
||||
public function __construct(
|
||||
callable $callable,
|
||||
private readonly Rule $rule
|
||||
private readonly Rule $rule,
|
||||
) {
|
||||
$this->callable = $callable;
|
||||
}
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
set_error_handler(static function (int $severity, string $message, ?string $filename, int $line): void {
|
||||
set_error_handler(static function (int $severity, string $message, string|null $filename, int $line): void {
|
||||
throw new ErrorException($message, 0, $severity, $filename, $line);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,10 @@ use function count;
|
|||
)]
|
||||
final class Callback extends Simple
|
||||
{
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
/** @var callable */
|
||||
private $callback;
|
||||
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
/** @var mixed[] */
|
||||
private readonly array $arguments;
|
||||
|
||||
public function __construct(callable $callback, mixed ...$arguments)
|
||||
|
|
@ -45,9 +41,7 @@ final class Callback extends Simple
|
|||
return (bool) call_user_func_array($this->callback, $this->getArguments($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
/** @return mixed[] */
|
||||
private function getArguments(mixed $input): array
|
||||
{
|
||||
$arguments = [$input];
|
||||
|
|
|
|||
|
|
@ -64,16 +64,14 @@ final class Cnpj extends Simple
|
|||
return $digits[13] == $check;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
/** @return int[] */
|
||||
private function getDigits(string $input): array
|
||||
{
|
||||
return array_map(
|
||||
'intval',
|
||||
str_split(
|
||||
(string) preg_replace('/\D/', '', $input)
|
||||
)
|
||||
(string) preg_replace('/\D/', '', $input),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ final readonly class Contains implements Rule
|
|||
{
|
||||
public function __construct(
|
||||
private mixed $containsValue,
|
||||
private bool $identical = false
|
||||
private bool $identical = false,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,9 +32,10 @@ final class ContainsAny extends Envelope
|
|||
}
|
||||
|
||||
$rules = $this->getRules($needles, $identical);
|
||||
|
||||
parent::__construct(
|
||||
count($rules) === 1 ? $rules[0] : new AnyOf(...$rules),
|
||||
['needles' => $needles]
|
||||
['needles' => $needles],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +50,7 @@ final class ContainsAny extends Envelope
|
|||
static function ($needle) use ($identical): Contains {
|
||||
return new Contains($needle, $identical);
|
||||
},
|
||||
$needles
|
||||
$needles,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,8 @@ abstract class Comparison implements Rule
|
|||
{
|
||||
use CanCompareValues;
|
||||
|
||||
abstract protected function compare(mixed $left, mixed $right): bool;
|
||||
|
||||
public function __construct(
|
||||
private readonly mixed $compareTo
|
||||
private readonly mixed $compareTo,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -37,4 +35,6 @@ abstract class Comparison implements Rule
|
|||
|
||||
return new Result($this->compare($left, $right), $input, $this, $parameters);
|
||||
}
|
||||
|
||||
abstract protected function compare(mixed $left, mixed $right): bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ abstract class Envelope implements Rule
|
|||
/** @param array<string, mixed> $parameters */
|
||||
public function __construct(
|
||||
private readonly Rule $rule,
|
||||
private readonly array $parameters = []
|
||||
private readonly array $parameters = [],
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@ use function iterator_to_array;
|
|||
|
||||
abstract class FilteredNonEmptyArray extends Wrapper
|
||||
{
|
||||
/** @param non-empty-array<mixed> $input */
|
||||
abstract protected function evaluateNonEmptyArray(array $input): Result;
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$iterableResult = (new IterableType())->evaluate($input);
|
||||
|
|
@ -38,8 +35,12 @@ abstract class FilteredNonEmptyArray extends Wrapper
|
|||
return $this->evaluateNonEmptyArray($array);
|
||||
}
|
||||
|
||||
/** @param non-empty-array<mixed> $input */
|
||||
abstract protected function evaluateNonEmptyArray(array $input): Result;
|
||||
|
||||
/**
|
||||
* @param iterable<mixed> $input
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
private function toArray(iterable $input): array
|
||||
|
|
|
|||
|
|
@ -19,12 +19,10 @@ use function str_split;
|
|||
|
||||
abstract class FilteredString implements Rule
|
||||
{
|
||||
public const TEMPLATE_EXTRA = '__extra__';
|
||||
public const string TEMPLATE_EXTRA = '__extra__';
|
||||
|
||||
private readonly string $additionalChars;
|
||||
|
||||
abstract protected function isValid(string $input): bool;
|
||||
|
||||
public function __construct(string ...$additionalChars)
|
||||
{
|
||||
$this->additionalChars = implode($additionalChars);
|
||||
|
|
@ -49,6 +47,8 @@ abstract class FilteredString implements Rule
|
|||
return new Result($isValid, $input, $this, $parameters, $template);
|
||||
}
|
||||
|
||||
abstract protected function isValid(string $input): bool;
|
||||
|
||||
private function filter(string $input): string
|
||||
{
|
||||
return str_replace(str_split($this->additionalChars), '', $input);
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ namespace Respect\Validation\Rules\Core;
|
|||
|
||||
interface Nameable
|
||||
{
|
||||
public function getName(): ?string;
|
||||
public function getName(): string|null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ final class Reducer extends Wrapper
|
|||
parent::__construct($rules === [] ? $rule1 : new AllOf($rule1, ...$rules));
|
||||
}
|
||||
|
||||
public function withTemplate(?string $template): self
|
||||
public function withTemplate(string|null $template): self
|
||||
{
|
||||
if ($template === null) {
|
||||
return $this;
|
||||
|
|
@ -30,7 +30,7 @@ final class Reducer extends Wrapper
|
|||
return new self(new Templated($this->rule, $template));
|
||||
}
|
||||
|
||||
public function withName(?string $name): self
|
||||
public function withName(string|null $name): self
|
||||
{
|
||||
if ($name === null) {
|
||||
return $this;
|
||||
|
|
@ -39,7 +39,7 @@ final class Reducer extends Wrapper
|
|||
return new self(new Named($this->rule, $name));
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
public function getName(): string|null
|
||||
{
|
||||
if ($this->rule instanceof Nameable) {
|
||||
return $this->rule->getName();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Respect\Validation\Rule;
|
|||
abstract class Wrapper implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly Rule $rule
|
||||
protected readonly Rule $rule,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@ final readonly class CountryCode implements Rule
|
|||
/** @param "alpha-2"|"alpha-3"|"numeric" $set */
|
||||
public function __construct(
|
||||
private string $set = 'alpha-2',
|
||||
?Countries $countries = null
|
||||
Countries|null $countries = null,
|
||||
) {
|
||||
if (!class_exists(Countries::class)) {
|
||||
throw new MissingComposerDependencyException(
|
||||
'SubdivisionCode rule requires PHP ISO Codes',
|
||||
'sokil/php-isocodes',
|
||||
'sokil/php-isocodes-db-only'
|
||||
'sokil/php-isocodes-db-only',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ final readonly class CountryCode implements Rule
|
|||
throw new InvalidRuleConstructorException(
|
||||
'"%s" is not a valid set for ISO 3166-1 (Available: %s)',
|
||||
$set,
|
||||
$availableOptions
|
||||
$availableOptions,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,17 +33,17 @@ use function preg_replace;
|
|||
)]
|
||||
final readonly class CreditCard implements Rule
|
||||
{
|
||||
public const TEMPLATE_BRANDED = '__branded__';
|
||||
public const ANY = 'Any';
|
||||
public const AMERICAN_EXPRESS = 'American Express';
|
||||
public const DINERS_CLUB = 'Diners Club';
|
||||
public const DISCOVER = 'Discover';
|
||||
public const JCB = 'JCB';
|
||||
public const MASTERCARD = 'MasterCard';
|
||||
public const VISA = 'Visa';
|
||||
public const RUPAY = 'RuPay';
|
||||
public const string TEMPLATE_BRANDED = '__branded__';
|
||||
public const string ANY = 'Any';
|
||||
public const string AMERICAN_EXPRESS = 'American Express';
|
||||
public const string DINERS_CLUB = 'Diners Club';
|
||||
public const string DISCOVER = 'Discover';
|
||||
public const string JCB = 'JCB';
|
||||
public const string MASTERCARD = 'MasterCard';
|
||||
public const string VISA = 'Visa';
|
||||
public const string RUPAY = 'RuPay';
|
||||
|
||||
private const BRAND_REGEX_LIST = [
|
||||
private const array BRAND_REGEX_LIST = [
|
||||
self::ANY => '/^[0-9]+$/',
|
||||
self::AMERICAN_EXPRESS => '/^3[47]\d{13}$/',
|
||||
self::DINERS_CLUB => '/^3(?:0[0-5]|[68]\d)\d{11}$/',
|
||||
|
|
@ -55,13 +55,13 @@ final readonly class CreditCard implements Rule
|
|||
];
|
||||
|
||||
public function __construct(
|
||||
private string $brand = self::ANY
|
||||
private string $brand = self::ANY,
|
||||
) {
|
||||
if (!isset(self::BRAND_REGEX_LIST[$brand])) {
|
||||
throw new InvalidRuleConstructorException(
|
||||
'"%s" is not a valid credit card brand (Available: %s)',
|
||||
$brand,
|
||||
array_keys(self::BRAND_REGEX_LIST)
|
||||
array_keys(self::BRAND_REGEX_LIST),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ final readonly class CreditCard implements Rule
|
|||
$input,
|
||||
$this,
|
||||
$parameters,
|
||||
$template
|
||||
$template,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@ final readonly class CurrencyCode implements Rule
|
|||
/** @param "alpha-3"|"numeric" $set */
|
||||
public function __construct(
|
||||
private string $set = 'alpha-3',
|
||||
?Currencies $currencies = null
|
||||
Currencies|null $currencies = null,
|
||||
) {
|
||||
if (!class_exists(Currencies::class)) {
|
||||
throw new MissingComposerDependencyException(
|
||||
'CurrencyCode rule requires PHP ISO Codes',
|
||||
'sokil/php-isocodes',
|
||||
'sokil/php-isocodes-db-only'
|
||||
'sokil/php-isocodes-db-only',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -47,9 +47,10 @@ final readonly class CurrencyCode implements Rule
|
|||
throw new InvalidRuleConstructorException(
|
||||
'"%s" is not a valid set for ISO 4217 (Available: %s)',
|
||||
$set,
|
||||
$availableSets
|
||||
$availableSets,
|
||||
);
|
||||
}
|
||||
|
||||
$this->currencies = $currencies ?? new Currencies();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ final readonly class Date implements Rule
|
|||
use CanValidateDateTime;
|
||||
|
||||
public function __construct(
|
||||
private string $format = 'Y-m-d'
|
||||
private string $format = 'Y-m-d',
|
||||
) {
|
||||
if (!preg_match('/^[djSFmMnYy\W]+$/', $format)) {
|
||||
throw new InvalidRuleConstructorException('"%s" is not a valid date format', $format);
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ final class DateTime implements Rule
|
|||
{
|
||||
use CanValidateDateTime;
|
||||
|
||||
public const TEMPLATE_FORMAT = '__format__';
|
||||
public const string TEMPLATE_FORMAT = '__format__';
|
||||
|
||||
public function __construct(
|
||||
private readonly ?string $format = null
|
||||
private readonly string|null $format = null,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,44 +26,44 @@ use function ucfirst;
|
|||
#[Template(
|
||||
'The number of {{type|trans}} between now and',
|
||||
'The number of {{type|trans}} between now and',
|
||||
self::TEMPLATE_STANDARD
|
||||
self::TEMPLATE_STANDARD,
|
||||
)]
|
||||
#[Template(
|
||||
'The number of {{type|trans}} between {{now}} and',
|
||||
'The number of {{type|trans}} between {{now}} and',
|
||||
self::TEMPLATE_CUSTOMIZED
|
||||
self::TEMPLATE_CUSTOMIZED,
|
||||
)]
|
||||
#[Template(
|
||||
'For comparison with {{now|raw}}, {{name}} must be a valid datetime',
|
||||
'For comparison with {{now|raw}}, {{name}} must not be a valid datetime',
|
||||
self::TEMPLATE_NOT_A_DATE
|
||||
self::TEMPLATE_NOT_A_DATE,
|
||||
)]
|
||||
#[Template(
|
||||
'For comparison with {{now|raw}}, {{name}} must be a valid datetime in the format {{sample|raw}}',
|
||||
'For comparison with {{now|raw}}, {{name}} must not be a valid datetime in the format {{sample|raw}}',
|
||||
self::TEMPLATE_WRONG_FORMAT
|
||||
self::TEMPLATE_WRONG_FORMAT,
|
||||
)]
|
||||
final readonly class DateTimeDiff implements Rule
|
||||
{
|
||||
use CanValidateDateTime;
|
||||
|
||||
public const TEMPLATE_CUSTOMIZED = '__customized__';
|
||||
public const TEMPLATE_NOT_A_DATE = '__not_a_date__';
|
||||
public const TEMPLATE_WRONG_FORMAT = '__wrong_format__';
|
||||
public const string TEMPLATE_CUSTOMIZED = '__customized__';
|
||||
public const string TEMPLATE_NOT_A_DATE = '__not_a_date__';
|
||||
public const string TEMPLATE_WRONG_FORMAT = '__wrong_format__';
|
||||
|
||||
/** @param "years"|"months"|"days"|"hours"|"minutes"|"seconds"|"microseconds" $type */
|
||||
public function __construct(
|
||||
private string $type,
|
||||
private Rule $rule,
|
||||
private ?string $format = null,
|
||||
private ?DateTimeImmutable $now = null,
|
||||
private string|null $format = null,
|
||||
private DateTimeImmutable|null $now = null,
|
||||
) {
|
||||
$availableTypes = ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'microseconds'];
|
||||
if (!in_array($this->type, $availableTypes, true)) {
|
||||
throw new InvalidRuleConstructorException(
|
||||
'"%s" is not a valid type of age (Available: %s)',
|
||||
$this->type,
|
||||
$availableTypes
|
||||
$availableTypes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ final readonly class DateTimeDiff implements Rule
|
|||
$this,
|
||||
$this->rule->evaluate($this->comparisonValue($now, $compareTo)),
|
||||
['type' => $this->type, 'now' => $nowPlaceholder],
|
||||
$nowPlaceholder === 'now' ? self::TEMPLATE_STANDARD : self::TEMPLATE_CUSTOMIZED
|
||||
$nowPlaceholder === 'now' ? self::TEMPLATE_STANDARD : self::TEMPLATE_CUSTOMIZED,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ final readonly class DateTimeDiff implements Rule
|
|||
return $now->format($this->format);
|
||||
}
|
||||
|
||||
private function createDateTimeObject(mixed $input): ?DateTimeInterface
|
||||
private function createDateTimeObject(mixed $input): DateTimeInterface|null
|
||||
{
|
||||
if ($input instanceof DateTimeInterface) {
|
||||
return $input;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use function var_export;
|
|||
final readonly class Decimal implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private int $decimals
|
||||
private int $decimals,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ final class Domain implements Rule
|
|||
new StringType(),
|
||||
new NoWhitespace(),
|
||||
new Contains('.'),
|
||||
new Length(new GreaterThanOrEqual(3))
|
||||
new Length(new GreaterThanOrEqual(3)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -86,10 +86,10 @@ final class Domain implements Rule
|
|||
new Not(new Contains('--')),
|
||||
new Callback(static function ($str) {
|
||||
return mb_substr_count($str, '--') == 1;
|
||||
})
|
||||
}),
|
||||
),
|
||||
new Not(new EndsWith('-'))
|
||||
)
|
||||
new Not(new EndsWith('-')),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,10 @@ final class Each extends FilteredNonEmptyArray
|
|||
foreach ($input as $key => $value) {
|
||||
$children[] = $this->rule->evaluate($value)->withPath($key);
|
||||
}
|
||||
|
||||
$hasPassed = array_reduce(
|
||||
$children,
|
||||
static fn ($carry, $childResult) => $carry && $childResult->hasPassed,
|
||||
static fn($carry, $childResult) => $carry && $childResult->hasPassed,
|
||||
true,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,13 +29,14 @@ use const FILTER_VALIDATE_EMAIL;
|
|||
)]
|
||||
final class Email extends Simple
|
||||
{
|
||||
private readonly ?EmailValidator $validator;
|
||||
private readonly EmailValidator|null $validator;
|
||||
|
||||
public function __construct(?EmailValidator $validator = null)
|
||||
public function __construct(EmailValidator|null $validator = null)
|
||||
{
|
||||
if ($validator === null && func_num_args() === 0 && class_exists(EmailValidator::class)) {
|
||||
$validator = new EmailValidator();
|
||||
}
|
||||
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ final readonly class EndsWith implements Rule
|
|||
{
|
||||
public function __construct(
|
||||
private mixed $endValue,
|
||||
private bool $identical = false
|
||||
private bool $identical = false,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use function is_scalar;
|
|||
final readonly class Equals implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private mixed $compareTo
|
||||
private mixed $compareTo,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use const PATHINFO_EXTENSION;
|
|||
final readonly class Extension implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private string $extension
|
||||
private string $extension,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Respect\Validation\Result;
|
|||
use Respect\Validation\Rule;
|
||||
|
||||
use function abs;
|
||||
use function is_integer;
|
||||
use function is_int;
|
||||
use function is_numeric;
|
||||
use function preg_match;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ use function preg_match;
|
|||
final readonly class Factor implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private int $dividend
|
||||
private int $dividend,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +50,6 @@ final readonly class Factor implements Rule
|
|||
|
||||
// The dividend divided by the input must be an integer if input is a
|
||||
// factor of the dividend.
|
||||
return new Result(is_integer($dividend / $input), $input, $this, $parameters);
|
||||
return new Result(is_int($dividend / $input), $input, $this, $parameters);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ use const FILTER_VALIDATE_URL;
|
|||
)]
|
||||
final class FilterVar extends Envelope
|
||||
{
|
||||
private const ALLOWED_FILTERS = [
|
||||
private const array ALLOWED_FILTERS = [
|
||||
FILTER_VALIDATE_BOOLEAN => 'is_bool',
|
||||
FILTER_VALIDATE_DOMAIN => 'is_string',
|
||||
FILTER_VALIDATE_EMAIL => 'is_string',
|
||||
|
|
@ -59,7 +59,7 @@ final class FilterVar extends Envelope
|
|||
|
||||
parent::__construct(new Callback(static function ($input) use ($filter, $arguments) {
|
||||
return (self::ALLOWED_FILTERS[$filter])(
|
||||
filter_var($input, ...$arguments)
|
||||
filter_var($input, ...$arguments),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ use function is_string;
|
|||
use function preg_match;
|
||||
use function str_split;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/National_identification_number#Finland
|
||||
*/
|
||||
/** @see https://en.wikipedia.org/wiki/National_identification_number#Finland */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid Finnish personal identity code',
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use function substr;
|
|||
)]
|
||||
final class Iban extends Simple
|
||||
{
|
||||
private const COUNTRIES_LENGTHS = [
|
||||
private const array COUNTRIES_LENGTHS = [
|
||||
'AL' => 28,
|
||||
'AD' => 24,
|
||||
'AT' => 20,
|
||||
|
|
@ -144,7 +144,7 @@ final class Iban extends Simple
|
|||
static function (array $match): string {
|
||||
return strval(ord($match[0]) - 55);
|
||||
},
|
||||
$reArrangedIban
|
||||
$reArrangedIban,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use Respect\Validation\Rule;
|
|||
final readonly class Identical implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private mixed $compareTo
|
||||
private mixed $compareTo,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use const FILEINFO_MIME_TYPE;
|
|||
final class Image extends Simple
|
||||
{
|
||||
public function __construct(
|
||||
private finfo $fileInfo = new finfo(FILEINFO_MIME_TYPE)
|
||||
private finfo $fileInfo = new finfo(FILEINFO_MIME_TYPE),
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use function preg_replace;
|
|||
)]
|
||||
final class Imei extends Simple
|
||||
{
|
||||
private const IMEI_SIZE = 15;
|
||||
private const int IMEI_SIZE = 15;
|
||||
|
||||
public function isValid(mixed $input): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ final readonly class In implements Rule
|
|||
{
|
||||
public function __construct(
|
||||
private mixed $haystack,
|
||||
private bool $compareIdentical = false
|
||||
private bool $compareIdentical = false,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ final readonly class Instance implements Rule
|
|||
{
|
||||
/** @param class-string $class */
|
||||
public function __construct(
|
||||
private string $class
|
||||
private string $class,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,17 +45,17 @@ use const PHP_INT_MAX;
|
|||
)]
|
||||
final class Ip implements Rule
|
||||
{
|
||||
public const TEMPLATE_NETWORK_RANGE = '__network_range__';
|
||||
public const string TEMPLATE_NETWORK_RANGE = '__network_range__';
|
||||
|
||||
private ?string $range = null;
|
||||
private string|null $range = null;
|
||||
|
||||
private ?string $startAddress = null;
|
||||
private string|null $startAddress = null;
|
||||
|
||||
private ?string $endAddress = null;
|
||||
private string|null $endAddress = null;
|
||||
|
||||
private ?string $mask = null;
|
||||
private string|null $mask = null;
|
||||
|
||||
public function __construct(string $range = '*', private ?int $options = null)
|
||||
public function __construct(string $range = '*', private int|null $options = null)
|
||||
{
|
||||
$this->parseRange($range);
|
||||
$this->range = $this->createRange();
|
||||
|
|
@ -84,7 +84,7 @@ final class Ip implements Rule
|
|||
return Result::passed($input, $this, $parameters, $template);
|
||||
}
|
||||
|
||||
private function createRange(): ?string
|
||||
private function createRange(): string|null
|
||||
{
|
||||
if ($this->startAddress && $this->endAddress) {
|
||||
return $this->startAddress . '-' . $this->endAddress;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,8 @@ use function sprintf;
|
|||
)]
|
||||
final class Isbn extends Simple
|
||||
{
|
||||
/**
|
||||
* @see https://howtodoinjava.com/regex/java-regex-validate-international-standard-book-number-isbns
|
||||
*/
|
||||
private const PIECES = [
|
||||
/** @see https://howtodoinjava.com/regex/java-regex-validate-international-standard-book-number-isbns */
|
||||
private const array PIECES = [
|
||||
'^(?:ISBN(?:-1[03])?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})',
|
||||
'[- 0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)',
|
||||
'(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$',
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use function is_array;
|
|||
final class KeyExists implements Rule, KeyRelated
|
||||
{
|
||||
public function __construct(
|
||||
private readonly int|string $key
|
||||
private readonly int|string $key,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,25 +33,25 @@ use function array_slice;
|
|||
#[Template(
|
||||
'{{name}} contains both missing and extra keys',
|
||||
'{{name}} contains no missing or extra keys.',
|
||||
self::TEMPLATE_BOTH
|
||||
self::TEMPLATE_BOTH,
|
||||
)]
|
||||
#[Template(
|
||||
'{{name}} contains extra keys',
|
||||
'{{name}} contains no extra keys',
|
||||
self::TEMPLATE_EXTRA_KEYS
|
||||
self::TEMPLATE_EXTRA_KEYS,
|
||||
)]
|
||||
#[Template(
|
||||
'{{name}} contains missing keys',
|
||||
'{{name}} contains no missing keys',
|
||||
self::TEMPLATE_MISSING_KEYS
|
||||
self::TEMPLATE_MISSING_KEYS,
|
||||
)]
|
||||
final readonly class KeySet implements Rule
|
||||
{
|
||||
public const TEMPLATE_BOTH = '__both__';
|
||||
public const TEMPLATE_EXTRA_KEYS = '__extra_keys__';
|
||||
public const TEMPLATE_MISSING_KEYS = '__missing_keys__';
|
||||
public const string TEMPLATE_BOTH = '__both__';
|
||||
public const string TEMPLATE_EXTRA_KEYS = '__extra_keys__';
|
||||
public const string TEMPLATE_MISSING_KEYS = '__missing_keys__';
|
||||
|
||||
private const MAX_DIFF_KEYS = 10;
|
||||
private const int MAX_DIFF_KEYS = 10;
|
||||
|
||||
/** @var array<KeyRelated> */
|
||||
private array $rules;
|
||||
|
|
@ -81,7 +81,7 @@ final readonly class KeySet implements Rule
|
|||
|
||||
$keys = new Reducer(...array_merge($this->rules, array_map(
|
||||
static fn(string|int $key) => new Not(new KeyExists($key)),
|
||||
array_slice(array_diff(array_keys($input), $this->allKeys), 0, self::MAX_DIFF_KEYS)
|
||||
array_slice(array_diff(array_keys($input), $this->allKeys), 0, self::MAX_DIFF_KEYS),
|
||||
)));
|
||||
$keysResult = $keys->evaluate($input);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ final readonly class LanguageCode implements Rule
|
|||
/** @param "alpha-2"|"alpha-3" $set */
|
||||
public function __construct(
|
||||
private readonly string $set = 'alpha-2',
|
||||
?Languages $languages = null
|
||||
Languages|null $languages = null,
|
||||
) {
|
||||
if (!class_exists(Countries::class)) {
|
||||
throw new MissingComposerDependencyException(
|
||||
'LanguageCode rule requires PHP ISO Codes',
|
||||
'sokil/php-isocodes',
|
||||
'sokil/php-isocodes-db-only'
|
||||
'sokil/php-isocodes-db-only',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ final readonly class LanguageCode implements Rule
|
|||
throw new InvalidRuleConstructorException(
|
||||
'"%s" is not a valid set for ISO 639-3 (Available: %s)',
|
||||
$set,
|
||||
$availableSets
|
||||
$availableSets,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use function is_scalar;
|
|||
final class LeapDate extends Simple
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $format
|
||||
private readonly string $format,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,16 +25,16 @@ use function ucfirst;
|
|||
#[Template(
|
||||
'The length of',
|
||||
'The length of',
|
||||
self::TEMPLATE_STANDARD
|
||||
self::TEMPLATE_STANDARD,
|
||||
)]
|
||||
#[Template(
|
||||
'{{name}} must be a countable value or a string',
|
||||
'{{name}} must not be a countable value or a string',
|
||||
self::TEMPLATE_WRONG_TYPE
|
||||
self::TEMPLATE_WRONG_TYPE,
|
||||
)]
|
||||
final class Length extends Wrapper
|
||||
{
|
||||
public const TEMPLATE_WRONG_TYPE = '__wrong_type__';
|
||||
public const string TEMPLATE_WRONG_TYPE = '__wrong_type__';
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
|
|
@ -47,7 +47,7 @@ final class Length extends Wrapper
|
|||
return Result::fromAdjacent($input, 'length', $this, $this->rule->evaluate($length));
|
||||
}
|
||||
|
||||
private function extractLength(mixed $input): ?int
|
||||
private function extractLength(mixed $input): int|null
|
||||
{
|
||||
if (is_string($input)) {
|
||||
return (int) mb_strlen($input);
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ use function array_map;
|
|||
use function count;
|
||||
use function str_split;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/Luhn_algorithm
|
||||
*/
|
||||
/** @see https://en.wikipedia.org/wiki/Luhn_algorithm */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid Luhn number',
|
||||
|
|
@ -42,9 +40,10 @@ final class Luhn extends Simple
|
|||
if ($parity == $i % 2) {
|
||||
$digit <<= 1;
|
||||
if (9 < $digit) {
|
||||
$digit = $digit - 9;
|
||||
$digit -= 9;
|
||||
}
|
||||
}
|
||||
|
||||
$sum += $digit;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ final readonly class Mimetype implements Rule
|
|||
{
|
||||
public function __construct(
|
||||
private string $mimetype,
|
||||
private finfo $fileInfo = new finfo()
|
||||
private finfo $fileInfo = new finfo(),
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ final readonly class Mimetype implements Rule
|
|||
$this->mimetype === $this->fileInfo->file($input, FILEINFO_MIME_TYPE),
|
||||
$input,
|
||||
$this,
|
||||
$parameters
|
||||
$parameters,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use Respect\Validation\Rule;
|
|||
final readonly class Multiple implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private int $multipleOf
|
||||
private int $multipleOf,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ final class Named extends Wrapper implements Nameable
|
|||
{
|
||||
public function __construct(
|
||||
Rule $rule,
|
||||
private readonly string $name
|
||||
private readonly string $name,
|
||||
) {
|
||||
parent::__construct($rule);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ use function floor;
|
|||
use function mb_strlen;
|
||||
use function str_split;
|
||||
|
||||
/**
|
||||
* @see (pt-br) Manual de Integração do Contribuinte v4.0.1 em http://www.nfe.fazenda.gov.br
|
||||
*/
|
||||
/** @see (pt-br) Manual de Integração do Contribuinte v4.0.1 em http://www.nfe.fazenda.gov.br */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid NFe access key',
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ use function mb_substr;
|
|||
use function preg_match;
|
||||
use function str_split;
|
||||
|
||||
/**
|
||||
* @see https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal
|
||||
*/
|
||||
/** @see https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid NIF',
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ use function is_scalar;
|
|||
use function preg_match;
|
||||
use function str_split;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/VAT_identification_number
|
||||
*/
|
||||
/** @see https://en.wikipedia.org/wiki/VAT_identification_number */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid Polish VAT identification number',
|
||||
|
|
@ -48,7 +46,7 @@ final class Nip extends Simple
|
|||
$calculateControlNumber += $digits[$i] * $weights[$i];
|
||||
}
|
||||
|
||||
$calculateControlNumber = $calculateControlNumber % 11;
|
||||
$calculateControlNumber %= 11;
|
||||
|
||||
return $targetControlNumber == $calculateControlNumber;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use Attribute;
|
|||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Rules\Core\Simple;
|
||||
|
||||
use function is_null;
|
||||
use function is_scalar;
|
||||
use function preg_match;
|
||||
|
||||
|
|
@ -26,7 +25,7 @@ final class NoWhitespace extends Simple
|
|||
{
|
||||
public function isValid(mixed $input): bool
|
||||
{
|
||||
if (is_null($input)) {
|
||||
if ($input === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,17 +33,17 @@ use function count;
|
|||
)]
|
||||
final class NoneOf extends Composite
|
||||
{
|
||||
public const TEMPLATE_ALL = '__all__';
|
||||
public const TEMPLATE_SOME = '__some__';
|
||||
public const string TEMPLATE_ALL = '__all__';
|
||||
public const string TEMPLATE_SOME = '__some__';
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(
|
||||
static fn (Rule $rule) => $rule->evaluate($input)->withToggledModeAndValidation(),
|
||||
$this->rules
|
||||
static fn(Rule $rule) => $rule->evaluate($input)->withToggledModeAndValidation(),
|
||||
$this->rules,
|
||||
);
|
||||
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry && $result->hasPassed, true);
|
||||
$failed = array_filter($children, static fn (Result $result): bool => !$result->hasPassed);
|
||||
$valid = array_reduce($children, static fn(bool $carry, Result $result) => $carry && $result->hasPassed, true);
|
||||
$failed = array_filter($children, static fn(Result $result): bool => !$result->hasPassed);
|
||||
$template = self::TEMPLATE_SOME;
|
||||
if (count($children) === count($failed)) {
|
||||
$template = self::TEMPLATE_ALL;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use function preg_match;
|
|||
)]
|
||||
final class NotEmoji extends Simple
|
||||
{
|
||||
private const RANGES = [
|
||||
private const array RANGES = [
|
||||
'\x{0023}\x{FE0F}\x{20E3}',
|
||||
'\x{0023}\x{20E3}',
|
||||
'\x{002A}\x{FE0F}\x{20E3}',
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ use Attribute;
|
|||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Rules\Core\Simple;
|
||||
|
||||
use function is_null;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be null',
|
||||
|
|
@ -24,6 +22,6 @@ final class NullType extends Simple
|
|||
{
|
||||
public function isValid(mixed $input): bool
|
||||
{
|
||||
return is_null($input);
|
||||
return $input === null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,27 +34,27 @@ use function usort;
|
|||
)]
|
||||
final class OneOf extends Composite
|
||||
{
|
||||
public const TEMPLATE_NONE = '__none__';
|
||||
public const TEMPLATE_MORE_THAN_ONE = '__more_than_one__';
|
||||
public const string TEMPLATE_NONE = '__none__';
|
||||
public const string TEMPLATE_MORE_THAN_ONE = '__more_than_one__';
|
||||
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$children = array_map(static fn(Rule $rule) => $rule->evaluate($input), $this->rules);
|
||||
$valid = array_reduce(
|
||||
$children,
|
||||
static fn (bool $carry, Result $result) => $carry xor $result->hasPassed,
|
||||
static fn(bool $carry, Result $result) => $carry xor $result->hasPassed,
|
||||
false,
|
||||
);
|
||||
$validChildren = array_filter($children, static fn (Result $result): bool => $result->hasPassed);
|
||||
$validChildren = array_filter($children, static fn(Result $result): bool => $result->hasPassed);
|
||||
$template = self::TEMPLATE_NONE;
|
||||
if (count($validChildren) > 1) {
|
||||
// Put the failed children at the top, so it makes sense in the main error message
|
||||
usort($children, static fn (Result $a, Result $b): int => $a->hasPassed <=> $b->hasPassed);
|
||||
usort($children, static fn(Result $a, Result $b): int => $a->hasPassed <=> $b->hasPassed);
|
||||
|
||||
$template = self::TEMPLATE_MORE_THAN_ONE;
|
||||
$children = array_map(
|
||||
static fn (Result $child) => $child->hasPassed ? $child->withToggledValidation() : $child,
|
||||
$children
|
||||
static fn(Result $child) => $child->hasPassed ? $child->withToggledValidation() : $child,
|
||||
$children,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,17 +35,17 @@ use function is_scalar;
|
|||
)]
|
||||
final class Phone implements Rule
|
||||
{
|
||||
public const TEMPLATE_FOR_COUNTRY = '__for_country__';
|
||||
public const TEMPLATE_INTERNATIONAL = '__international__';
|
||||
public const string TEMPLATE_FOR_COUNTRY = '__for_country__';
|
||||
public const string TEMPLATE_INTERNATIONAL = '__international__';
|
||||
|
||||
private readonly ?Countries\Country $country;
|
||||
private readonly Countries\Country|null $country;
|
||||
|
||||
public function __construct(?string $countryCode = null, ?Countries $countries = null)
|
||||
public function __construct(string|null $countryCode = null, Countries|null $countries = null)
|
||||
{
|
||||
if (!class_exists(PhoneNumberUtil::class)) {
|
||||
throw new MissingComposerDependencyException(
|
||||
'Phone rule libphonenumber for PHP',
|
||||
'giggsey/libphonenumber-for-php'
|
||||
'giggsey/libphonenumber-for-php',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ final class Phone implements Rule
|
|||
throw new MissingComposerDependencyException(
|
||||
'Phone rule with country code requires PHP ISO Codes',
|
||||
'sokil/php-isocodes',
|
||||
'sokil/php-isocodes-db-only'
|
||||
'sokil/php-isocodes-db-only',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ use function is_scalar;
|
|||
use function ord;
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/Polish_identity_card
|
||||
*/
|
||||
/** @see https://en.wikipedia.org/wiki/Polish_identity_card */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid Polish Identity Card number',
|
||||
|
|
@ -27,10 +25,10 @@ use function preg_match;
|
|||
)]
|
||||
final class PolishIdCard extends Simple
|
||||
{
|
||||
private const ASCII_CODE_0 = 48;
|
||||
private const ASCII_CODE_7 = 55;
|
||||
private const ASCII_CODE_9 = 57;
|
||||
private const ASCII_CODE_A = 65;
|
||||
private const int ASCII_CODE_0 = 48;
|
||||
private const int ASCII_CODE_7 = 55;
|
||||
private const int ASCII_CODE_9 = 57;
|
||||
private const int ASCII_CODE_A = 65;
|
||||
|
||||
public function isValid(mixed $input): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@ use function is_string;
|
|||
use function str_split;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* @see https://pt.wikipedia.org/wiki/N%C3%BAmero_de_identifica%C3%A7%C3%A3o_fiscal
|
||||
*/
|
||||
/** @see https://pt.wikipedia.org/wiki/N%C3%BAmero_de_identifica%C3%A7%C3%A3o_fiscal */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a Portuguese NIF',
|
||||
|
|
@ -48,7 +46,7 @@ final class PortugueseNif extends Simple
|
|||
return false;
|
||||
}
|
||||
|
||||
$digits = array_map(static fn (string $digit) => intval($digit), str_split($input));
|
||||
$digits = array_map(static fn(string $digit) => intval($digit), str_split($input));
|
||||
|
||||
// Validate first and second digits
|
||||
switch ($digits[0]) {
|
||||
|
|
@ -59,6 +57,7 @@ final class PortugueseNif extends Simple
|
|||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case 7:
|
||||
switch ($digits[1]) {
|
||||
|
|
@ -74,6 +73,7 @@ final class PortugueseNif extends Simple
|
|||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case 9:
|
||||
switch ($digits[1]) {
|
||||
|
|
@ -85,6 +85,7 @@ final class PortugueseNif extends Simple
|
|||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -93,7 +94,7 @@ final class PortugueseNif extends Simple
|
|||
// Validate check digit
|
||||
$checkDigit = array_pop($digits);
|
||||
$digitKeys = array_keys($digits);
|
||||
$sumTerms = array_map(static fn (int $digit, int $position) => $digit * (9 - $position), $digits, $digitKeys);
|
||||
$sumTerms = array_map(static fn(int $digit, int $position) => $digit * (9 - $position), $digits, $digitKeys);
|
||||
$sum = array_sum($sumTerms);
|
||||
$modulus = $sum % 11;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ use Respect\Validation\Exceptions\InvalidRuleConstructorException;
|
|||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Rules\Core\Envelope;
|
||||
|
||||
/**
|
||||
* @see http://download.geonames.org/export/dump/countryInfo.txt
|
||||
*/
|
||||
/** @see http://download.geonames.org/export/dump/countryInfo.txt */
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
||||
#[Template(
|
||||
'{{name}} must be a valid postal code on {{countryCode}}',
|
||||
|
|
@ -24,9 +22,9 @@ use Respect\Validation\Rules\Core\Envelope;
|
|||
)]
|
||||
final class PostalCode extends Envelope
|
||||
{
|
||||
private const DEFAULT_PATTERN = '/^$/';
|
||||
private const string DEFAULT_PATTERN = '/^$/';
|
||||
|
||||
private const POSTAL_CODES_EXTRA = [
|
||||
private const array POSTAL_CODES_EXTRA = [
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
'AM' => ['/^\d\d\d\d$/', '/^(\d{4})$/'],
|
||||
'BR' => ['/^\d\d\d\d\d-\d\d\d$/', '/^\d{5}-?\d{3}$/'],
|
||||
|
|
@ -40,7 +38,7 @@ final class PostalCode extends Envelope
|
|||
// phpcs:enable Generic.Files.LineLength.TooLong
|
||||
];
|
||||
|
||||
private const POSTAL_CODES = [
|
||||
private const array POSTAL_CODES = [
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
'AD' => ['/^AD\d\d\d$/', '/^(?:AD)*(\d{3})$/'],
|
||||
'AL' => ['/^\d\d\d\d$/', '/^(\d{4})$/'],
|
||||
|
|
@ -216,9 +214,9 @@ final class PostalCode extends Envelope
|
|||
|
||||
parent::__construct(
|
||||
new Regex(
|
||||
self::POSTAL_CODES_EXTRA[$countryCode][$formatted ? 0 : 1] ?? self::POSTAL_CODES[$countryCode][$formatted ? 0 : 1] ?? self::DEFAULT_PATTERN
|
||||
self::POSTAL_CODES_EXTRA[$countryCode][$formatted ? 0 : 1] ?? self::POSTAL_CODES[$countryCode][$formatted ? 0 : 1] ?? self::DEFAULT_PATTERN,
|
||||
),
|
||||
['countryCode' => $countryCode]
|
||||
['countryCode' => $countryCode],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use function is_object;
|
|||
final readonly class PropertyExists implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private string $propertyName
|
||||
private string $propertyName,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use function preg_match;
|
|||
final readonly class Regex implements Rule
|
||||
{
|
||||
public function __construct(
|
||||
private string $regex
|
||||
private string $regex,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,18 +27,18 @@ use function ucfirst;
|
|||
#[Template(
|
||||
'The size in {{unit|trans}} of',
|
||||
'The size in {{unit|trans}} of',
|
||||
Size::TEMPLATE_STANDARD
|
||||
Size::TEMPLATE_STANDARD,
|
||||
)]
|
||||
#[Template(
|
||||
'{{name}} must be a filename or an instance of SplFileInfo or a PSR-7 interface',
|
||||
'{{name}} must not be a filename or an instance of SplFileInfo or a PSR-7 interface',
|
||||
self::TEMPLATE_WRONG_TYPE
|
||||
self::TEMPLATE_WRONG_TYPE,
|
||||
)]
|
||||
final class Size extends Wrapper
|
||||
{
|
||||
public const TEMPLATE_WRONG_TYPE = '__wrong_type__';
|
||||
public const string TEMPLATE_WRONG_TYPE = '__wrong_type__';
|
||||
|
||||
private const DATA_STORAGE_UNITS = [
|
||||
private const array DATA_STORAGE_UNITS = [
|
||||
'B' => ['name' => 'bytes', 'bytes' => 1],
|
||||
'KB' => ['name' => 'kilobytes', 'bytes' => 1024],
|
||||
'MB' => ['name' => 'megabytes', 'bytes' => 1024 ** 2],
|
||||
|
|
@ -53,7 +53,7 @@ final class Size extends Wrapper
|
|||
/** @param "B"|"KB"|"MB"|"GB"|"TB"|"PB"|"EB"|"ZB"|"YB" $unit */
|
||||
public function __construct(
|
||||
private readonly string $unit,
|
||||
Rule $rule
|
||||
Rule $rule,
|
||||
) {
|
||||
if (!isset(self::DATA_STORAGE_UNITS[$unit])) {
|
||||
throw new InvalidRuleConstructorException('"%s" is not a recognized data storage unit.', $unit);
|
||||
|
|
@ -76,7 +76,7 @@ final class Size extends Wrapper
|
|||
return Result::fromAdjacent($input, 'size', $this, $result, $parameters);
|
||||
}
|
||||
|
||||
private function getSize(mixed $input): ?int
|
||||
private function getSize(mixed $input): int|null
|
||||
{
|
||||
if (is_string($input)) {
|
||||
return (int) filesize($input);
|
||||
|
|
|
|||
|
|
@ -34,20 +34,20 @@ use function str_split;
|
|||
)]
|
||||
final readonly class Sorted implements Rule
|
||||
{
|
||||
public const TEMPLATE_ASCENDING = '__ascending__';
|
||||
public const TEMPLATE_DESCENDING = '__descending__';
|
||||
public const string TEMPLATE_ASCENDING = '__ascending__';
|
||||
public const string TEMPLATE_DESCENDING = '__descending__';
|
||||
|
||||
public const ASCENDING = 'ASC';
|
||||
public const DESCENDING = 'DESC';
|
||||
public const string ASCENDING = 'ASC';
|
||||
public const string DESCENDING = 'DESC';
|
||||
|
||||
public function __construct(
|
||||
private string $direction
|
||||
private string $direction,
|
||||
) {
|
||||
if ($direction !== self::ASCENDING && $direction !== self::DESCENDING) {
|
||||
throw new InvalidRuleConstructorException(
|
||||
'Direction should be either "%s" or "%s"',
|
||||
self::ASCENDING,
|
||||
self::DESCENDING
|
||||
self::DESCENDING,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ final readonly class StartsWith implements Rule
|
|||
{
|
||||
public function __construct(
|
||||
private mixed $startValue,
|
||||
private bool $identical = false
|
||||
private bool $identical = false,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue