Compare commits

...

7 commits

Author SHA1 Message Date
Henrique Moody d7dc0f2b4e
Refactor the "NullOr" rule and related classes
This commit will rename the "Nullable" rule to "NullOr" while soft
deprecating the old name. It should work the same as the previous one
but with a different name. It will also prefix the result ID, allowing
more message customization.

While working on it, I realized that the prefix "nullOr" had a typo,
and it was using "nullOf" instead. I fixed that, too.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:55:50 +01:00
Henrique Moody 707dcae65f
Refactor the "UndefOr" rule and related classes
This commit will rename the "Optional" rule to"UndefOr" while soft
deprecating the old name. It should work the same as the previous one
but with a different name. It will also prefix the result ID, allowing
more message customization.

While working on it, I realized that the prefix "undefOr" had a typo,
and it was using "undefOf" instead. I fixed that, too.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:35:36 +01:00
Henrique Moody eeaea466ac
Prefix IDs of wrapper rule results
Because some rules work more as a prefix, it makes sense to prefix their
result ID. That will allow for a more intuitive templating, especially
when using those rules as prefixes.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:23:29 +01:00
Henrique Moody 8573bc5d45
Do not overwrite "IDs" when updating names
When you have a chain of rules in the Validation and overwrite the name
with "setName()," it's impossible to get the messages from all rules in
the chain as an array because they all have the same name.

These changes will change that behavior by creating a more explicit
distinction between "IDs" and "names." The "IDs" will remain
unchangeable, while we can always overwrite the names. That means that
the array messages will look more similar to the chain, and it will be
possible to overwrite the messages from multiple rules in the same
chain.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:12:44 +01:00
Henrique Moody 9322cd6375
Do not create results with siblings in the When rule
When creating a result with a sibling in the When rule, the result
generates an unhelpful message. In most of the use cases of the When
rule, the initial rule ("when") is only helpful in determining which
will be the "real" rule to use.

Those changes will change the When rule not to generate results with
siblings.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-25 23:47:25 +01:00
Henrique Moody fefe905e0b
Include "__root__" when getting message as an array
When converting an object into an array, we exclude the message root
message from it. Since we're using a convention to template those
messages as an array, we could also use the same convention to return
those messages.

While working on it, I noticed that the name "__self__" wasn't
reflecting what that really meant, so I renamed it "__root__" because it
better reflects the meaning of those messages/templates.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-25 22:38:19 +01:00
Henrique Moody d1f108dc87
Make proper use of exceptions in rules
This commit will ensure that all rules that cannot be created because of
invalid arguments in the constructor will throw the
InvalidRuleConstructorException. It will also make ComponentException
extend LogicException, which makes it easier to determine that the
client has improperly used the library.

I also introduced some tests for two exceptions with logic in their
constructor.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-25 22:09:02 +01:00
102 changed files with 1571 additions and 1119 deletions

View file

@ -25,9 +25,12 @@ use Respect\Validation\Mixins\StaticNot;
use Respect\Validation\Mixins\StaticNullOr;
use Respect\Validation\Mixins\StaticProperty;
use Respect\Validation\Mixins\StaticUndefOr;
use Respect\Validation\Rules\NullOr;
use Respect\Validation\Rules\UndefOr;
use Respect\Validation\Validatable;
function addMethodToInterface(
string $originalName,
InterfaceType $interfaceType,
ReflectionClass $reflection,
?string $prefix,
@ -42,7 +45,7 @@ function addMethodToInterface(
return;
}
$name = $prefix ? $prefix . ucfirst($reflection->getShortName()) : lcfirst($reflection->getShortName());
$name = $prefix ? $prefix . ucfirst($originalName) : lcfirst($originalName);
$method = $interfaceType->addMethod($name)->setPublic()->setReturnType(ChainedValidator::class);
if (str_starts_with($interfaceType->getName(), 'Static')) {
$method->setStatic();
@ -65,6 +68,14 @@ function addMethodToInterface(
$method->addComment(preg_replace('@(/\*\* *| +\* +| +\*/)@', '', $commend));
}
if ($originalName === 'Optional') {
$method->addComment('@deprecated Use {@see undefOr()} instead.');
}
if ($originalName === 'Nullable') {
$method->addComment('@deprecated Use {@see nullOr()} instead.');
}
foreach ($reflrectionConstructor->getParameters() as $reflectionParameter) {
if ($reflectionParameter->isVariadic()) {
$method->setVariadic();
@ -150,6 +161,10 @@ function overwriteFile(string $content, string $basename): void
'KeyExists',
'KeyOptional',
'KeySet',
'Optional',
'NullOr',
'Nullable',
'UndefOr',
'Property',
'PropertyExists',
'PropertyOptional',
@ -160,10 +175,10 @@ function overwriteFile(string $content, string $basename): void
['Length', 'length', $numberRelatedRules, []],
['Max', 'max', $numberRelatedRules, []],
['Min', 'min', $numberRelatedRules, []],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotBlank', 'NotEmoji', 'NotOptional', 'Optional']],
['NullOr', 'nullOf', [], ['Nullable', 'Optional']],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotBlank', 'NotEmoji', 'NotOptional', 'NullOr', 'UndefOr', 'Optional']],
['NullOr', 'nullOr', [], ['Nullable', 'NullOr', 'Optional', 'UndefOr']],
['Property', 'property', [], $structureRelatedRules],
['UndefOr', 'undefOf', [], ['Nullable', 'Optional']],
['UndefOr', 'undefOr', [], ['Nullable', 'NullOr', 'Optional', 'UndefOr']],
['Validator', null, [], []],
];
@ -179,6 +194,12 @@ function overwriteFile(string $content, string $basename): void
continue;
}
$names[$reflection->getShortName()] = $reflection;
if ($className === UndefOr::class) {
$names['Optional'] = $reflection;
}
if ($className === NullOr::class) {
$names['Nullable'] = $reflection;
}
}
ksort($names);
@ -212,9 +233,9 @@ function overwriteFile(string $content, string $basename): void
$staticInterface->addExtend(StaticUndefOr::class);
}
foreach ($names as $reflection) {
addMethodToInterface($staticInterface, $reflection, $prefix, $allowList, $denyList);
addMethodToInterface($chainedInterface, $reflection, $prefix, $allowList, $denyList);
foreach ($names as $originalName => $reflection) {
addMethodToInterface($originalName, $staticInterface, $reflection, $prefix, $allowList, $denyList);
addMethodToInterface($originalName, $chainedInterface, $reflection, $prefix, $allowList, $denyList);
}
$printer = new Printer();

View file

@ -1,31 +0,0 @@
# Optional
- `Optional(Validatable $rule)`
Validates if the given input is optional or not. By _optional_ we consider `null`
or an empty string (`''`).
```php
v::optional(v::alpha())->validate(''); // true
v::optional(v::digit())->validate(null); // true
```
## Categorization
- Nesting
## Changelog
Version | Description
--------|-------------
1.0.0 | Created
***
See also:
- [NoWhitespace](NoWhitespace.md)
- [NotBlank](NotBlank.md)
- [NotEmpty](NotEmpty.md)
- [NotOptional](NotOptional.md)
- [NullType](NullType.md)
- [Nullable](Nullable.md)

45
docs/rules/UndefOr.md Normal file
View file

@ -0,0 +1,45 @@
# UndefOr
- `UndefOr(Validatable $rule)`
Validates if the given input is undefined or not.
By _undefined_ we consider `null` or an empty string (`''`), which implies that the input is not set. This is particularly useful when validating form fields
```php
v::undefOr(v::alpha())->validate(''); // true
v::undefOr(v::digit())->validate(null); // true
v::undefOr(v::alpha())->validate('username'); // true
v::undefOr(v::alpha())->validate('has1number'); // false
```
## Note
For convenience, you can use the `undefOr` as a prefix to any rule:
```php
v::undefOrEmail()->validate('not an email'); // false
v::undefOrBetween(1, 3)->validate(2); // true
```
## Categorization
- Nesting
## Changelog
| Version | Description |
|--------:|--------------------------------------|
| 3.0.0 | Renamed from "Optional" to "UndefOr" |
| 1.0.0 | Created |
***
See also:
- [NoWhitespace](NoWhitespace.md)
- [NotBlank](NotBlank.md)
- [NotEmpty](NotEmpty.md)
- [NotOptional](NotOptional.md)
- [NullType](NullType.md)
- [Nullable](Nullable.md)

View file

@ -9,9 +9,9 @@ declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use Exception;
use LogicException;
use Throwable;
class ComponentException extends Exception implements Throwable
class ComponentException extends LogicException implements Throwable
{
}

View file

@ -17,6 +17,7 @@ use Respect\Validation\Message\Parameter\Processor;
use Respect\Validation\Message\Parameter\Raw;
use Respect\Validation\Message\Parameter\Stringify;
use Respect\Validation\Message\Parameter\Trans;
use Respect\Validation\Transformers\Aliases;
use Respect\Validation\Transformers\DeprecatedAttribute;
use Respect\Validation\Transformers\DeprecatedKey;
use Respect\Validation\Transformers\DeprecatedKeyNested;
@ -59,7 +60,7 @@ final class Factory
new DeprecatedKey(
new DeprecatedKeyValue(
new DeprecatedMinAndMax(
new DeprecatedKeyNested(new DeprecatedLength(new DeprecatedType(new Prefix())))
new DeprecatedKeyNested(new DeprecatedLength(new DeprecatedType(new Aliases(new Prefix()))))
)
)
)

View file

@ -100,6 +100,12 @@ final class StandardFormatter implements Formatter
$messages[$child->id] = current($messages[$child->id]);
}
if (count($messages) > 1) {
$self = ['__root__' => $this->renderer->render($this->getTemplated($result, $selectedTemplates))];
return $self + $messages;
}
return $messages;
}
@ -110,8 +116,8 @@ final class StandardFormatter implements Formatter
return $result;
}
if (!isset($templates[$result->id]) && isset($templates['__self__'])) {
return $result->withTemplate($templates['__self__']);
if (!isset($templates[$result->id]) && isset($templates['__root__'])) {
return $result->withTemplate($templates['__root__']);
}
if (!isset($templates[$result->id])) {
@ -141,7 +147,7 @@ final class StandardFormatter implements Formatter
return false;
}
return isset($templates['__self__']) || isset($templates[$result->id]);
return isset($templates['__root__']) || isset($templates[$result->id]);
}
/**

View file

@ -257,8 +257,6 @@ interface ChainedKey
public function keyNullType(int|string $key): ChainedValidator;
public function keyNullable(int|string $key, Validatable $rule): ChainedValidator;
public function keyNumber(int|string $key): ChainedValidator;
public function keyNumericVal(int|string $key): ChainedValidator;
@ -274,8 +272,6 @@ interface ChainedKey
Validatable ...$rules,
): ChainedValidator;
public function keyOptional(int|string $key, Validatable $rule): ChainedValidator;
public function keyPerfectSquare(int|string $key): ChainedValidator;
public function keyPesel(int|string $key): ChainedValidator;

View file

@ -236,8 +236,6 @@ interface ChainedNot
public function notNullType(): ChainedValidator;
public function notNullable(Validatable $rule): ChainedValidator;
public function notNumber(): ChainedValidator;
public function notNumericVal(): ChainedValidator;

View file

@ -13,341 +13,341 @@ use Respect\Validation\Validatable;
interface ChainedNullOr
{
public function nullOfAllOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOrAllOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOfAlnum(string ...$additionalChars): ChainedValidator;
public function nullOrAlnum(string ...$additionalChars): ChainedValidator;
public function nullOfAlpha(string ...$additionalChars): ChainedValidator;
public function nullOrAlpha(string ...$additionalChars): ChainedValidator;
public function nullOfAlwaysInvalid(): ChainedValidator;
public function nullOrAlwaysInvalid(): ChainedValidator;
public function nullOfAlwaysValid(): ChainedValidator;
public function nullOrAlwaysValid(): ChainedValidator;
public function nullOfAnyOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOrAnyOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOfArrayType(): ChainedValidator;
public function nullOrArrayType(): ChainedValidator;
public function nullOfArrayVal(): ChainedValidator;
public function nullOrArrayVal(): ChainedValidator;
public function nullOfBase(
public function nullOrBase(
int $base,
string $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
): ChainedValidator;
public function nullOfBase64(): ChainedValidator;
public function nullOrBase64(): ChainedValidator;
public function nullOfBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public function nullOrBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public function nullOfBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public function nullOrBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public function nullOfBoolType(): ChainedValidator;
public function nullOrBoolType(): ChainedValidator;
public function nullOfBoolVal(): ChainedValidator;
public function nullOrBoolVal(): ChainedValidator;
public function nullOfBsn(): ChainedValidator;
public function nullOrBsn(): ChainedValidator;
public function nullOfCall(callable $callable, Validatable $rule): ChainedValidator;
public function nullOrCall(callable $callable, Validatable $rule): ChainedValidator;
public function nullOfCallableType(): ChainedValidator;
public function nullOrCallableType(): ChainedValidator;
public function nullOfCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public function nullOrCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public function nullOfCharset(string $charset, string ...$charsets): ChainedValidator;
public function nullOrCharset(string $charset, string ...$charsets): ChainedValidator;
public function nullOfCnh(): ChainedValidator;
public function nullOrCnh(): ChainedValidator;
public function nullOfCnpj(): ChainedValidator;
public function nullOrCnpj(): ChainedValidator;
public function nullOfConsecutive(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOrConsecutive(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOfConsonant(string ...$additionalChars): ChainedValidator;
public function nullOrConsonant(string ...$additionalChars): ChainedValidator;
public function nullOfContains(mixed $containsValue, bool $identical = false): ChainedValidator;
public function nullOrContains(mixed $containsValue, bool $identical = false): ChainedValidator;
/**
* @param non-empty-array<mixed> $needles
*/
public function nullOfContainsAny(array $needles, bool $identical = false): ChainedValidator;
public function nullOrContainsAny(array $needles, bool $identical = false): ChainedValidator;
public function nullOfControl(string ...$additionalChars): ChainedValidator;
public function nullOrControl(string ...$additionalChars): ChainedValidator;
public function nullOfCountable(): ChainedValidator;
public function nullOrCountable(): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3"|"numeric" $set
*/
public function nullOfCountryCode(string $set = 'alpha-2'): ChainedValidator;
public function nullOrCountryCode(string $set = 'alpha-2'): ChainedValidator;
public function nullOfCpf(): ChainedValidator;
public function nullOrCpf(): ChainedValidator;
public function nullOfCreditCard(string $brand = 'Any'): ChainedValidator;
public function nullOrCreditCard(string $brand = 'Any'): ChainedValidator;
/**
* @param "alpha-3"|"numeric" $set
*/
public function nullOfCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public function nullOrCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public function nullOfDate(string $format = 'Y-m-d'): ChainedValidator;
public function nullOrDate(string $format = 'Y-m-d'): ChainedValidator;
public function nullOfDateTime(?string $format = null): ChainedValidator;
public function nullOrDateTime(?string $format = null): ChainedValidator;
public function nullOfDecimal(int $decimals): ChainedValidator;
public function nullOrDecimal(int $decimals): ChainedValidator;
public function nullOfDigit(string ...$additionalChars): ChainedValidator;
public function nullOrDigit(string ...$additionalChars): ChainedValidator;
public function nullOfDirectory(): ChainedValidator;
public function nullOrDirectory(): ChainedValidator;
public function nullOfDomain(bool $tldCheck = true): ChainedValidator;
public function nullOrDomain(bool $tldCheck = true): ChainedValidator;
public function nullOfEach(Validatable $rule): ChainedValidator;
public function nullOrEach(Validatable $rule): ChainedValidator;
public function nullOfEmail(): ChainedValidator;
public function nullOrEmail(): ChainedValidator;
public function nullOfEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public function nullOrEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public function nullOfEquals(mixed $compareTo): ChainedValidator;
public function nullOrEquals(mixed $compareTo): ChainedValidator;
public function nullOfEquivalent(mixed $compareTo): ChainedValidator;
public function nullOrEquivalent(mixed $compareTo): ChainedValidator;
public function nullOfEven(): ChainedValidator;
public function nullOrEven(): ChainedValidator;
public function nullOfExecutable(): ChainedValidator;
public function nullOrExecutable(): ChainedValidator;
public function nullOfExists(): ChainedValidator;
public function nullOrExists(): ChainedValidator;
public function nullOfExtension(string $extension): ChainedValidator;
public function nullOrExtension(string $extension): ChainedValidator;
public function nullOfFactor(int $dividend): ChainedValidator;
public function nullOrFactor(int $dividend): ChainedValidator;
public function nullOfFalseVal(): ChainedValidator;
public function nullOrFalseVal(): ChainedValidator;
public function nullOfFibonacci(): ChainedValidator;
public function nullOrFibonacci(): ChainedValidator;
public function nullOfFile(): ChainedValidator;
public function nullOrFile(): ChainedValidator;
public function nullOfFilterVar(int $filter, mixed $options = null): ChainedValidator;
public function nullOrFilterVar(int $filter, mixed $options = null): ChainedValidator;
public function nullOfFinite(): ChainedValidator;
public function nullOrFinite(): ChainedValidator;
public function nullOfFloatType(): ChainedValidator;
public function nullOrFloatType(): ChainedValidator;
public function nullOfFloatVal(): ChainedValidator;
public function nullOrFloatVal(): ChainedValidator;
public function nullOfGraph(string ...$additionalChars): ChainedValidator;
public function nullOrGraph(string ...$additionalChars): ChainedValidator;
public function nullOfGreaterThan(mixed $compareTo): ChainedValidator;
public function nullOrGreaterThan(mixed $compareTo): ChainedValidator;
public function nullOfGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public function nullOrGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public function nullOfHetu(): ChainedValidator;
public function nullOrHetu(): ChainedValidator;
public function nullOfHexRgbColor(): ChainedValidator;
public function nullOrHexRgbColor(): ChainedValidator;
public function nullOfIban(): ChainedValidator;
public function nullOrIban(): ChainedValidator;
public function nullOfIdentical(mixed $compareTo): ChainedValidator;
public function nullOrIdentical(mixed $compareTo): ChainedValidator;
public function nullOfImage(): ChainedValidator;
public function nullOrImage(): ChainedValidator;
public function nullOfImei(): ChainedValidator;
public function nullOrImei(): ChainedValidator;
public function nullOfIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public function nullOrIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public function nullOfInfinite(): ChainedValidator;
public function nullOrInfinite(): ChainedValidator;
/**
* @param class-string $class
*/
public function nullOfInstance(string $class): ChainedValidator;
public function nullOrInstance(string $class): ChainedValidator;
public function nullOfIntType(): ChainedValidator;
public function nullOrIntType(): ChainedValidator;
public function nullOfIntVal(): ChainedValidator;
public function nullOrIntVal(): ChainedValidator;
public function nullOfIp(string $range = '*', ?int $options = null): ChainedValidator;
public function nullOrIp(string $range = '*', ?int $options = null): ChainedValidator;
public function nullOfIsbn(): ChainedValidator;
public function nullOrIsbn(): ChainedValidator;
public function nullOfIterableType(): ChainedValidator;
public function nullOrIterableType(): ChainedValidator;
public function nullOfIterableVal(): ChainedValidator;
public function nullOrIterableVal(): ChainedValidator;
public function nullOfJson(): ChainedValidator;
public function nullOrJson(): ChainedValidator;
public function nullOfKey(string|int $key, Validatable $rule): ChainedValidator;
public function nullOrKey(string|int $key, Validatable $rule): ChainedValidator;
public function nullOfKeyExists(string|int $key): ChainedValidator;
public function nullOrKeyExists(string|int $key): ChainedValidator;
public function nullOfKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public function nullOrKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public function nullOfKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
public function nullOrKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3" $set
*/
public function nullOfLanguageCode(string $set = 'alpha-2'): ChainedValidator;
public function nullOrLanguageCode(string $set = 'alpha-2'): ChainedValidator;
/**
* @param callable(mixed): Validatable $ruleCreator
*/
public function nullOfLazy(callable $ruleCreator): ChainedValidator;
public function nullOrLazy(callable $ruleCreator): ChainedValidator;
public function nullOfLeapDate(string $format): ChainedValidator;
public function nullOrLeapDate(string $format): ChainedValidator;
public function nullOfLeapYear(): ChainedValidator;
public function nullOrLeapYear(): ChainedValidator;
public function nullOfLength(Validatable $rule): ChainedValidator;
public function nullOrLength(Validatable $rule): ChainedValidator;
public function nullOfLessThan(mixed $compareTo): ChainedValidator;
public function nullOrLessThan(mixed $compareTo): ChainedValidator;
public function nullOfLessThanOrEqual(mixed $compareTo): ChainedValidator;
public function nullOrLessThanOrEqual(mixed $compareTo): ChainedValidator;
public function nullOfLowercase(): ChainedValidator;
public function nullOrLowercase(): ChainedValidator;
public function nullOfLuhn(): ChainedValidator;
public function nullOrLuhn(): ChainedValidator;
public function nullOfMacAddress(): ChainedValidator;
public function nullOrMacAddress(): ChainedValidator;
public function nullOfMax(Validatable $rule): ChainedValidator;
public function nullOrMax(Validatable $rule): ChainedValidator;
public function nullOfMaxAge(int $age, ?string $format = null): ChainedValidator;
public function nullOrMaxAge(int $age, ?string $format = null): ChainedValidator;
public function nullOfMimetype(string $mimetype): ChainedValidator;
public function nullOrMimetype(string $mimetype): ChainedValidator;
public function nullOfMin(Validatable $rule): ChainedValidator;
public function nullOrMin(Validatable $rule): ChainedValidator;
public function nullOfMinAge(int $age, ?string $format = null): ChainedValidator;
public function nullOrMinAge(int $age, ?string $format = null): ChainedValidator;
public function nullOfMultiple(int $multipleOf): ChainedValidator;
public function nullOrMultiple(int $multipleOf): ChainedValidator;
public function nullOfNegative(): ChainedValidator;
public function nullOrNegative(): ChainedValidator;
public function nullOfNfeAccessKey(): ChainedValidator;
public function nullOrNfeAccessKey(): ChainedValidator;
public function nullOfNif(): ChainedValidator;
public function nullOrNif(): ChainedValidator;
public function nullOfNip(): ChainedValidator;
public function nullOrNip(): ChainedValidator;
public function nullOfNo(bool $useLocale = false): ChainedValidator;
public function nullOrNo(bool $useLocale = false): ChainedValidator;
public function nullOfNoWhitespace(): ChainedValidator;
public function nullOrNoWhitespace(): ChainedValidator;
public function nullOfNoneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOrNoneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOfNot(Validatable $rule): ChainedValidator;
public function nullOrNot(Validatable $rule): ChainedValidator;
public function nullOfNotBlank(): ChainedValidator;
public function nullOrNotBlank(): ChainedValidator;
public function nullOfNotEmoji(): ChainedValidator;
public function nullOrNotEmoji(): ChainedValidator;
public function nullOfNotEmpty(): ChainedValidator;
public function nullOrNotEmpty(): ChainedValidator;
public function nullOfNotOptional(): ChainedValidator;
public function nullOrNotOptional(): ChainedValidator;
public function nullOfNullType(): ChainedValidator;
public function nullOrNullType(): ChainedValidator;
public function nullOfNumber(): ChainedValidator;
public function nullOrNumber(): ChainedValidator;
public function nullOfNumericVal(): ChainedValidator;
public function nullOrNumericVal(): ChainedValidator;
public function nullOfObjectType(): ChainedValidator;
public function nullOrObjectType(): ChainedValidator;
public function nullOfOdd(): ChainedValidator;
public function nullOrOdd(): ChainedValidator;
public function nullOfOneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOrOneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function nullOfPerfectSquare(): ChainedValidator;
public function nullOrPerfectSquare(): ChainedValidator;
public function nullOfPesel(): ChainedValidator;
public function nullOrPesel(): ChainedValidator;
public function nullOfPhone(?string $countryCode = null): ChainedValidator;
public function nullOrPhone(?string $countryCode = null): ChainedValidator;
public function nullOfPhpLabel(): ChainedValidator;
public function nullOrPhpLabel(): ChainedValidator;
public function nullOfPis(): ChainedValidator;
public function nullOrPis(): ChainedValidator;
public function nullOfPolishIdCard(): ChainedValidator;
public function nullOrPolishIdCard(): ChainedValidator;
public function nullOfPortugueseNif(): ChainedValidator;
public function nullOrPortugueseNif(): ChainedValidator;
public function nullOfPositive(): ChainedValidator;
public function nullOrPositive(): ChainedValidator;
public function nullOfPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public function nullOrPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public function nullOfPrimeNumber(): ChainedValidator;
public function nullOrPrimeNumber(): ChainedValidator;
public function nullOfPrintable(string ...$additionalChars): ChainedValidator;
public function nullOrPrintable(string ...$additionalChars): ChainedValidator;
public function nullOfProperty(string $propertyName, Validatable $rule): ChainedValidator;
public function nullOrProperty(string $propertyName, Validatable $rule): ChainedValidator;
public function nullOfPropertyExists(string $propertyName): ChainedValidator;
public function nullOrPropertyExists(string $propertyName): ChainedValidator;
public function nullOfPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public function nullOrPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public function nullOfPublicDomainSuffix(): ChainedValidator;
public function nullOrPublicDomainSuffix(): ChainedValidator;
public function nullOfPunct(string ...$additionalChars): ChainedValidator;
public function nullOrPunct(string ...$additionalChars): ChainedValidator;
public function nullOfReadable(): ChainedValidator;
public function nullOrReadable(): ChainedValidator;
public function nullOfRegex(string $regex): ChainedValidator;
public function nullOrRegex(string $regex): ChainedValidator;
public function nullOfResourceType(): ChainedValidator;
public function nullOrResourceType(): ChainedValidator;
public function nullOfRoman(): ChainedValidator;
public function nullOrRoman(): ChainedValidator;
public function nullOfScalarVal(): ChainedValidator;
public function nullOrScalarVal(): ChainedValidator;
public function nullOfSize(string|int|null $minSize = null, string|int|null $maxSize = null): ChainedValidator;
public function nullOrSize(string|int|null $minSize = null, string|int|null $maxSize = null): ChainedValidator;
public function nullOfSlug(): ChainedValidator;
public function nullOrSlug(): ChainedValidator;
public function nullOfSorted(string $direction): ChainedValidator;
public function nullOrSorted(string $direction): ChainedValidator;
public function nullOfSpace(string ...$additionalChars): ChainedValidator;
public function nullOrSpace(string ...$additionalChars): ChainedValidator;
public function nullOfStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public function nullOrStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public function nullOfStringType(): ChainedValidator;
public function nullOrStringType(): ChainedValidator;
public function nullOfStringVal(): ChainedValidator;
public function nullOrStringVal(): ChainedValidator;
public function nullOfSubdivisionCode(string $countryCode): ChainedValidator;
public function nullOrSubdivisionCode(string $countryCode): ChainedValidator;
/**
* @param mixed[] $superset
*/
public function nullOfSubset(array $superset): ChainedValidator;
public function nullOrSubset(array $superset): ChainedValidator;
public function nullOfSymbolicLink(): ChainedValidator;
public function nullOrSymbolicLink(): ChainedValidator;
public function nullOfTime(string $format = 'H:i:s'): ChainedValidator;
public function nullOrTime(string $format = 'H:i:s'): ChainedValidator;
public function nullOfTld(): ChainedValidator;
public function nullOrTld(): ChainedValidator;
public function nullOfTrueVal(): ChainedValidator;
public function nullOrTrueVal(): ChainedValidator;
public function nullOfUnique(): ChainedValidator;
public function nullOrUnique(): ChainedValidator;
public function nullOfUploaded(): ChainedValidator;
public function nullOrUploaded(): ChainedValidator;
public function nullOfUppercase(): ChainedValidator;
public function nullOrUppercase(): ChainedValidator;
public function nullOfUrl(): ChainedValidator;
public function nullOrUrl(): ChainedValidator;
public function nullOfUuid(?int $version = null): ChainedValidator;
public function nullOrUuid(?int $version = null): ChainedValidator;
public function nullOfVersion(): ChainedValidator;
public function nullOrVersion(): ChainedValidator;
public function nullOfVideoUrl(?string $service = null): ChainedValidator;
public function nullOrVideoUrl(?string $service = null): ChainedValidator;
public function nullOfVowel(string ...$additionalChars): ChainedValidator;
public function nullOrVowel(string ...$additionalChars): ChainedValidator;
public function nullOfWhen(Validatable $when, Validatable $then, ?Validatable $else = null): ChainedValidator;
public function nullOrWhen(Validatable $when, Validatable $then, ?Validatable $else = null): ChainedValidator;
public function nullOfWritable(): ChainedValidator;
public function nullOrWritable(): ChainedValidator;
public function nullOfXdigit(string ...$additionalChars): ChainedValidator;
public function nullOrXdigit(string ...$additionalChars): ChainedValidator;
public function nullOfYes(bool $useLocale = false): ChainedValidator;
public function nullOrYes(bool $useLocale = false): ChainedValidator;
}

View file

@ -269,8 +269,6 @@ interface ChainedProperty
public function propertyNullType(string $propertyName): ChainedValidator;
public function propertyNullable(string $propertyName, Validatable $rule): ChainedValidator;
public function propertyNumber(string $propertyName): ChainedValidator;
public function propertyNumericVal(string $propertyName): ChainedValidator;
@ -286,8 +284,6 @@ interface ChainedProperty
Validatable ...$rules,
): ChainedValidator;
public function propertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public function propertyPerfectSquare(string $propertyName): ChainedValidator;
public function propertyPesel(string $propertyName): ChainedValidator;

View file

@ -13,345 +13,345 @@ use Respect\Validation\Validatable;
interface ChainedUndefOr
{
public function undefOfAllOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOrAllOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOfAlnum(string ...$additionalChars): ChainedValidator;
public function undefOrAlnum(string ...$additionalChars): ChainedValidator;
public function undefOfAlpha(string ...$additionalChars): ChainedValidator;
public function undefOrAlpha(string ...$additionalChars): ChainedValidator;
public function undefOfAlwaysInvalid(): ChainedValidator;
public function undefOrAlwaysInvalid(): ChainedValidator;
public function undefOfAlwaysValid(): ChainedValidator;
public function undefOrAlwaysValid(): ChainedValidator;
public function undefOfAnyOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOrAnyOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOfArrayType(): ChainedValidator;
public function undefOrArrayType(): ChainedValidator;
public function undefOfArrayVal(): ChainedValidator;
public function undefOrArrayVal(): ChainedValidator;
public function undefOfBase(
public function undefOrBase(
int $base,
string $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
): ChainedValidator;
public function undefOfBase64(): ChainedValidator;
public function undefOrBase64(): ChainedValidator;
public function undefOfBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public function undefOrBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public function undefOfBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public function undefOrBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public function undefOfBoolType(): ChainedValidator;
public function undefOrBoolType(): ChainedValidator;
public function undefOfBoolVal(): ChainedValidator;
public function undefOrBoolVal(): ChainedValidator;
public function undefOfBsn(): ChainedValidator;
public function undefOrBsn(): ChainedValidator;
public function undefOfCall(callable $callable, Validatable $rule): ChainedValidator;
public function undefOrCall(callable $callable, Validatable $rule): ChainedValidator;
public function undefOfCallableType(): ChainedValidator;
public function undefOrCallableType(): ChainedValidator;
public function undefOfCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public function undefOrCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public function undefOfCharset(string $charset, string ...$charsets): ChainedValidator;
public function undefOrCharset(string $charset, string ...$charsets): ChainedValidator;
public function undefOfCnh(): ChainedValidator;
public function undefOrCnh(): ChainedValidator;
public function undefOfCnpj(): ChainedValidator;
public function undefOrCnpj(): ChainedValidator;
public function undefOfConsecutive(
public function undefOrConsecutive(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public function undefOfConsonant(string ...$additionalChars): ChainedValidator;
public function undefOrConsonant(string ...$additionalChars): ChainedValidator;
public function undefOfContains(mixed $containsValue, bool $identical = false): ChainedValidator;
public function undefOrContains(mixed $containsValue, bool $identical = false): ChainedValidator;
/**
* @param non-empty-array<mixed> $needles
*/
public function undefOfContainsAny(array $needles, bool $identical = false): ChainedValidator;
public function undefOrContainsAny(array $needles, bool $identical = false): ChainedValidator;
public function undefOfControl(string ...$additionalChars): ChainedValidator;
public function undefOrControl(string ...$additionalChars): ChainedValidator;
public function undefOfCountable(): ChainedValidator;
public function undefOrCountable(): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3"|"numeric" $set
*/
public function undefOfCountryCode(string $set = 'alpha-2'): ChainedValidator;
public function undefOrCountryCode(string $set = 'alpha-2'): ChainedValidator;
public function undefOfCpf(): ChainedValidator;
public function undefOrCpf(): ChainedValidator;
public function undefOfCreditCard(string $brand = 'Any'): ChainedValidator;
public function undefOrCreditCard(string $brand = 'Any'): ChainedValidator;
/**
* @param "alpha-3"|"numeric" $set
*/
public function undefOfCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public function undefOrCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public function undefOfDate(string $format = 'Y-m-d'): ChainedValidator;
public function undefOrDate(string $format = 'Y-m-d'): ChainedValidator;
public function undefOfDateTime(?string $format = null): ChainedValidator;
public function undefOrDateTime(?string $format = null): ChainedValidator;
public function undefOfDecimal(int $decimals): ChainedValidator;
public function undefOrDecimal(int $decimals): ChainedValidator;
public function undefOfDigit(string ...$additionalChars): ChainedValidator;
public function undefOrDigit(string ...$additionalChars): ChainedValidator;
public function undefOfDirectory(): ChainedValidator;
public function undefOrDirectory(): ChainedValidator;
public function undefOfDomain(bool $tldCheck = true): ChainedValidator;
public function undefOrDomain(bool $tldCheck = true): ChainedValidator;
public function undefOfEach(Validatable $rule): ChainedValidator;
public function undefOrEach(Validatable $rule): ChainedValidator;
public function undefOfEmail(): ChainedValidator;
public function undefOrEmail(): ChainedValidator;
public function undefOfEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public function undefOrEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public function undefOfEquals(mixed $compareTo): ChainedValidator;
public function undefOrEquals(mixed $compareTo): ChainedValidator;
public function undefOfEquivalent(mixed $compareTo): ChainedValidator;
public function undefOrEquivalent(mixed $compareTo): ChainedValidator;
public function undefOfEven(): ChainedValidator;
public function undefOrEven(): ChainedValidator;
public function undefOfExecutable(): ChainedValidator;
public function undefOrExecutable(): ChainedValidator;
public function undefOfExists(): ChainedValidator;
public function undefOrExists(): ChainedValidator;
public function undefOfExtension(string $extension): ChainedValidator;
public function undefOrExtension(string $extension): ChainedValidator;
public function undefOfFactor(int $dividend): ChainedValidator;
public function undefOrFactor(int $dividend): ChainedValidator;
public function undefOfFalseVal(): ChainedValidator;
public function undefOrFalseVal(): ChainedValidator;
public function undefOfFibonacci(): ChainedValidator;
public function undefOrFibonacci(): ChainedValidator;
public function undefOfFile(): ChainedValidator;
public function undefOrFile(): ChainedValidator;
public function undefOfFilterVar(int $filter, mixed $options = null): ChainedValidator;
public function undefOrFilterVar(int $filter, mixed $options = null): ChainedValidator;
public function undefOfFinite(): ChainedValidator;
public function undefOrFinite(): ChainedValidator;
public function undefOfFloatType(): ChainedValidator;
public function undefOrFloatType(): ChainedValidator;
public function undefOfFloatVal(): ChainedValidator;
public function undefOrFloatVal(): ChainedValidator;
public function undefOfGraph(string ...$additionalChars): ChainedValidator;
public function undefOrGraph(string ...$additionalChars): ChainedValidator;
public function undefOfGreaterThan(mixed $compareTo): ChainedValidator;
public function undefOrGreaterThan(mixed $compareTo): ChainedValidator;
public function undefOfGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public function undefOrGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public function undefOfHetu(): ChainedValidator;
public function undefOrHetu(): ChainedValidator;
public function undefOfHexRgbColor(): ChainedValidator;
public function undefOrHexRgbColor(): ChainedValidator;
public function undefOfIban(): ChainedValidator;
public function undefOrIban(): ChainedValidator;
public function undefOfIdentical(mixed $compareTo): ChainedValidator;
public function undefOrIdentical(mixed $compareTo): ChainedValidator;
public function undefOfImage(): ChainedValidator;
public function undefOrImage(): ChainedValidator;
public function undefOfImei(): ChainedValidator;
public function undefOrImei(): ChainedValidator;
public function undefOfIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public function undefOrIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public function undefOfInfinite(): ChainedValidator;
public function undefOrInfinite(): ChainedValidator;
/**
* @param class-string $class
*/
public function undefOfInstance(string $class): ChainedValidator;
public function undefOrInstance(string $class): ChainedValidator;
public function undefOfIntType(): ChainedValidator;
public function undefOrIntType(): ChainedValidator;
public function undefOfIntVal(): ChainedValidator;
public function undefOrIntVal(): ChainedValidator;
public function undefOfIp(string $range = '*', ?int $options = null): ChainedValidator;
public function undefOrIp(string $range = '*', ?int $options = null): ChainedValidator;
public function undefOfIsbn(): ChainedValidator;
public function undefOrIsbn(): ChainedValidator;
public function undefOfIterableType(): ChainedValidator;
public function undefOrIterableType(): ChainedValidator;
public function undefOfIterableVal(): ChainedValidator;
public function undefOrIterableVal(): ChainedValidator;
public function undefOfJson(): ChainedValidator;
public function undefOrJson(): ChainedValidator;
public function undefOfKey(string|int $key, Validatable $rule): ChainedValidator;
public function undefOrKey(string|int $key, Validatable $rule): ChainedValidator;
public function undefOfKeyExists(string|int $key): ChainedValidator;
public function undefOrKeyExists(string|int $key): ChainedValidator;
public function undefOfKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public function undefOrKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public function undefOfKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
public function undefOrKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3" $set
*/
public function undefOfLanguageCode(string $set = 'alpha-2'): ChainedValidator;
public function undefOrLanguageCode(string $set = 'alpha-2'): ChainedValidator;
/**
* @param callable(mixed): Validatable $ruleCreator
*/
public function undefOfLazy(callable $ruleCreator): ChainedValidator;
public function undefOrLazy(callable $ruleCreator): ChainedValidator;
public function undefOfLeapDate(string $format): ChainedValidator;
public function undefOrLeapDate(string $format): ChainedValidator;
public function undefOfLeapYear(): ChainedValidator;
public function undefOrLeapYear(): ChainedValidator;
public function undefOfLength(Validatable $rule): ChainedValidator;
public function undefOrLength(Validatable $rule): ChainedValidator;
public function undefOfLessThan(mixed $compareTo): ChainedValidator;
public function undefOrLessThan(mixed $compareTo): ChainedValidator;
public function undefOfLessThanOrEqual(mixed $compareTo): ChainedValidator;
public function undefOrLessThanOrEqual(mixed $compareTo): ChainedValidator;
public function undefOfLowercase(): ChainedValidator;
public function undefOrLowercase(): ChainedValidator;
public function undefOfLuhn(): ChainedValidator;
public function undefOrLuhn(): ChainedValidator;
public function undefOfMacAddress(): ChainedValidator;
public function undefOrMacAddress(): ChainedValidator;
public function undefOfMax(Validatable $rule): ChainedValidator;
public function undefOrMax(Validatable $rule): ChainedValidator;
public function undefOfMaxAge(int $age, ?string $format = null): ChainedValidator;
public function undefOrMaxAge(int $age, ?string $format = null): ChainedValidator;
public function undefOfMimetype(string $mimetype): ChainedValidator;
public function undefOrMimetype(string $mimetype): ChainedValidator;
public function undefOfMin(Validatable $rule): ChainedValidator;
public function undefOrMin(Validatable $rule): ChainedValidator;
public function undefOfMinAge(int $age, ?string $format = null): ChainedValidator;
public function undefOrMinAge(int $age, ?string $format = null): ChainedValidator;
public function undefOfMultiple(int $multipleOf): ChainedValidator;
public function undefOrMultiple(int $multipleOf): ChainedValidator;
public function undefOfNegative(): ChainedValidator;
public function undefOrNegative(): ChainedValidator;
public function undefOfNfeAccessKey(): ChainedValidator;
public function undefOrNfeAccessKey(): ChainedValidator;
public function undefOfNif(): ChainedValidator;
public function undefOrNif(): ChainedValidator;
public function undefOfNip(): ChainedValidator;
public function undefOrNip(): ChainedValidator;
public function undefOfNo(bool $useLocale = false): ChainedValidator;
public function undefOrNo(bool $useLocale = false): ChainedValidator;
public function undefOfNoWhitespace(): ChainedValidator;
public function undefOrNoWhitespace(): ChainedValidator;
public function undefOfNoneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOrNoneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOfNot(Validatable $rule): ChainedValidator;
public function undefOrNot(Validatable $rule): ChainedValidator;
public function undefOfNotBlank(): ChainedValidator;
public function undefOrNotBlank(): ChainedValidator;
public function undefOfNotEmoji(): ChainedValidator;
public function undefOrNotEmoji(): ChainedValidator;
public function undefOfNotEmpty(): ChainedValidator;
public function undefOrNotEmpty(): ChainedValidator;
public function undefOfNotOptional(): ChainedValidator;
public function undefOrNotOptional(): ChainedValidator;
public function undefOfNullType(): ChainedValidator;
public function undefOrNullType(): ChainedValidator;
public function undefOfNumber(): ChainedValidator;
public function undefOrNumber(): ChainedValidator;
public function undefOfNumericVal(): ChainedValidator;
public function undefOrNumericVal(): ChainedValidator;
public function undefOfObjectType(): ChainedValidator;
public function undefOrObjectType(): ChainedValidator;
public function undefOfOdd(): ChainedValidator;
public function undefOrOdd(): ChainedValidator;
public function undefOfOneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOrOneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
public function undefOfPerfectSquare(): ChainedValidator;
public function undefOrPerfectSquare(): ChainedValidator;
public function undefOfPesel(): ChainedValidator;
public function undefOrPesel(): ChainedValidator;
public function undefOfPhone(?string $countryCode = null): ChainedValidator;
public function undefOrPhone(?string $countryCode = null): ChainedValidator;
public function undefOfPhpLabel(): ChainedValidator;
public function undefOrPhpLabel(): ChainedValidator;
public function undefOfPis(): ChainedValidator;
public function undefOrPis(): ChainedValidator;
public function undefOfPolishIdCard(): ChainedValidator;
public function undefOrPolishIdCard(): ChainedValidator;
public function undefOfPortugueseNif(): ChainedValidator;
public function undefOrPortugueseNif(): ChainedValidator;
public function undefOfPositive(): ChainedValidator;
public function undefOrPositive(): ChainedValidator;
public function undefOfPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public function undefOrPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public function undefOfPrimeNumber(): ChainedValidator;
public function undefOrPrimeNumber(): ChainedValidator;
public function undefOfPrintable(string ...$additionalChars): ChainedValidator;
public function undefOrPrintable(string ...$additionalChars): ChainedValidator;
public function undefOfProperty(string $propertyName, Validatable $rule): ChainedValidator;
public function undefOrProperty(string $propertyName, Validatable $rule): ChainedValidator;
public function undefOfPropertyExists(string $propertyName): ChainedValidator;
public function undefOrPropertyExists(string $propertyName): ChainedValidator;
public function undefOfPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public function undefOrPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public function undefOfPublicDomainSuffix(): ChainedValidator;
public function undefOrPublicDomainSuffix(): ChainedValidator;
public function undefOfPunct(string ...$additionalChars): ChainedValidator;
public function undefOrPunct(string ...$additionalChars): ChainedValidator;
public function undefOfReadable(): ChainedValidator;
public function undefOrReadable(): ChainedValidator;
public function undefOfRegex(string $regex): ChainedValidator;
public function undefOrRegex(string $regex): ChainedValidator;
public function undefOfResourceType(): ChainedValidator;
public function undefOrResourceType(): ChainedValidator;
public function undefOfRoman(): ChainedValidator;
public function undefOrRoman(): ChainedValidator;
public function undefOfScalarVal(): ChainedValidator;
public function undefOrScalarVal(): ChainedValidator;
public function undefOfSize(string|int|null $minSize = null, string|int|null $maxSize = null): ChainedValidator;
public function undefOrSize(string|int|null $minSize = null, string|int|null $maxSize = null): ChainedValidator;
public function undefOfSlug(): ChainedValidator;
public function undefOrSlug(): ChainedValidator;
public function undefOfSorted(string $direction): ChainedValidator;
public function undefOrSorted(string $direction): ChainedValidator;
public function undefOfSpace(string ...$additionalChars): ChainedValidator;
public function undefOrSpace(string ...$additionalChars): ChainedValidator;
public function undefOfStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public function undefOrStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public function undefOfStringType(): ChainedValidator;
public function undefOrStringType(): ChainedValidator;
public function undefOfStringVal(): ChainedValidator;
public function undefOrStringVal(): ChainedValidator;
public function undefOfSubdivisionCode(string $countryCode): ChainedValidator;
public function undefOrSubdivisionCode(string $countryCode): ChainedValidator;
/**
* @param mixed[] $superset
*/
public function undefOfSubset(array $superset): ChainedValidator;
public function undefOrSubset(array $superset): ChainedValidator;
public function undefOfSymbolicLink(): ChainedValidator;
public function undefOrSymbolicLink(): ChainedValidator;
public function undefOfTime(string $format = 'H:i:s'): ChainedValidator;
public function undefOrTime(string $format = 'H:i:s'): ChainedValidator;
public function undefOfTld(): ChainedValidator;
public function undefOrTld(): ChainedValidator;
public function undefOfTrueVal(): ChainedValidator;
public function undefOrTrueVal(): ChainedValidator;
public function undefOfUnique(): ChainedValidator;
public function undefOrUnique(): ChainedValidator;
public function undefOfUploaded(): ChainedValidator;
public function undefOrUploaded(): ChainedValidator;
public function undefOfUppercase(): ChainedValidator;
public function undefOrUppercase(): ChainedValidator;
public function undefOfUrl(): ChainedValidator;
public function undefOrUrl(): ChainedValidator;
public function undefOfUuid(?int $version = null): ChainedValidator;
public function undefOrUuid(?int $version = null): ChainedValidator;
public function undefOfVersion(): ChainedValidator;
public function undefOrVersion(): ChainedValidator;
public function undefOfVideoUrl(?string $service = null): ChainedValidator;
public function undefOrVideoUrl(?string $service = null): ChainedValidator;
public function undefOfVowel(string ...$additionalChars): ChainedValidator;
public function undefOrVowel(string ...$additionalChars): ChainedValidator;
public function undefOfWhen(Validatable $when, Validatable $then, ?Validatable $else = null): ChainedValidator;
public function undefOrWhen(Validatable $when, Validatable $then, ?Validatable $else = null): ChainedValidator;
public function undefOfWritable(): ChainedValidator;
public function undefOrWritable(): ChainedValidator;
public function undefOfXdigit(string ...$additionalChars): ChainedValidator;
public function undefOrXdigit(string ...$additionalChars): ChainedValidator;
public function undefOfYes(bool $useLocale = false): ChainedValidator;
public function undefOrYes(bool $useLocale = false): ChainedValidator;
}

View file

@ -253,8 +253,13 @@ interface ChainedValidator extends
public function notOptional(): ChainedValidator;
public function nullOr(Validatable $rule): ChainedValidator;
public function nullType(): ChainedValidator;
/**
* @deprecated Use {@see nullOr()} instead.
*/
public function nullable(Validatable $rule): ChainedValidator;
public function number(): ChainedValidator;
@ -267,6 +272,9 @@ interface ChainedValidator extends
public function oneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
/**
* @deprecated Use {@see undefOr()} instead.
*/
public function optional(Validatable $rule): ChainedValidator;
public function perfectSquare(): ChainedValidator;
@ -340,6 +348,8 @@ interface ChainedValidator extends
public function trueVal(): ChainedValidator;
public function undefOr(Validatable $rule): ChainedValidator;
public function unique(): ChainedValidator;
public function uploaded(): ChainedValidator;

View file

@ -261,8 +261,6 @@ interface StaticKey
public static function keyNullType(int|string $key): ChainedValidator;
public static function keyNullable(int|string $key, Validatable $rule): ChainedValidator;
public static function keyNumber(int|string $key): ChainedValidator;
public static function keyNumericVal(int|string $key): ChainedValidator;
@ -278,8 +276,6 @@ interface StaticKey
Validatable ...$rules,
): ChainedValidator;
public static function keyOptional(int|string $key, Validatable $rule): ChainedValidator;
public static function keyPerfectSquare(int|string $key): ChainedValidator;
public static function keyPesel(int|string $key): ChainedValidator;

View file

@ -240,8 +240,6 @@ interface StaticNot
public static function notNullType(): ChainedValidator;
public static function notNullable(Validatable $rule): ChainedValidator;
public static function notNumber(): ChainedValidator;
public static function notNumericVal(): ChainedValidator;

View file

@ -13,368 +13,368 @@ use Respect\Validation\Validatable;
interface StaticNullOr
{
public static function nullOfAllOf(
public static function nullOrAllOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function nullOfAlnum(string ...$additionalChars): ChainedValidator;
public static function nullOrAlnum(string ...$additionalChars): ChainedValidator;
public static function nullOfAlpha(string ...$additionalChars): ChainedValidator;
public static function nullOrAlpha(string ...$additionalChars): ChainedValidator;
public static function nullOfAlwaysInvalid(): ChainedValidator;
public static function nullOrAlwaysInvalid(): ChainedValidator;
public static function nullOfAlwaysValid(): ChainedValidator;
public static function nullOrAlwaysValid(): ChainedValidator;
public static function nullOfAnyOf(
public static function nullOrAnyOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function nullOfArrayType(): ChainedValidator;
public static function nullOrArrayType(): ChainedValidator;
public static function nullOfArrayVal(): ChainedValidator;
public static function nullOrArrayVal(): ChainedValidator;
public static function nullOfBase(
public static function nullOrBase(
int $base,
string $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
): ChainedValidator;
public static function nullOfBase64(): ChainedValidator;
public static function nullOrBase64(): ChainedValidator;
public static function nullOfBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public static function nullOrBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public static function nullOfBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public static function nullOrBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public static function nullOfBoolType(): ChainedValidator;
public static function nullOrBoolType(): ChainedValidator;
public static function nullOfBoolVal(): ChainedValidator;
public static function nullOrBoolVal(): ChainedValidator;
public static function nullOfBsn(): ChainedValidator;
public static function nullOrBsn(): ChainedValidator;
public static function nullOfCall(callable $callable, Validatable $rule): ChainedValidator;
public static function nullOrCall(callable $callable, Validatable $rule): ChainedValidator;
public static function nullOfCallableType(): ChainedValidator;
public static function nullOrCallableType(): ChainedValidator;
public static function nullOfCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public static function nullOrCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public static function nullOfCharset(string $charset, string ...$charsets): ChainedValidator;
public static function nullOrCharset(string $charset, string ...$charsets): ChainedValidator;
public static function nullOfCnh(): ChainedValidator;
public static function nullOrCnh(): ChainedValidator;
public static function nullOfCnpj(): ChainedValidator;
public static function nullOrCnpj(): ChainedValidator;
public static function nullOfConsecutive(
public static function nullOrConsecutive(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function nullOfConsonant(string ...$additionalChars): ChainedValidator;
public static function nullOrConsonant(string ...$additionalChars): ChainedValidator;
public static function nullOfContains(mixed $containsValue, bool $identical = false): ChainedValidator;
public static function nullOrContains(mixed $containsValue, bool $identical = false): ChainedValidator;
/**
* @param non-empty-array<mixed> $needles
*/
public static function nullOfContainsAny(array $needles, bool $identical = false): ChainedValidator;
public static function nullOrContainsAny(array $needles, bool $identical = false): ChainedValidator;
public static function nullOfControl(string ...$additionalChars): ChainedValidator;
public static function nullOrControl(string ...$additionalChars): ChainedValidator;
public static function nullOfCountable(): ChainedValidator;
public static function nullOrCountable(): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3"|"numeric" $set
*/
public static function nullOfCountryCode(string $set = 'alpha-2'): ChainedValidator;
public static function nullOrCountryCode(string $set = 'alpha-2'): ChainedValidator;
public static function nullOfCpf(): ChainedValidator;
public static function nullOrCpf(): ChainedValidator;
public static function nullOfCreditCard(string $brand = 'Any'): ChainedValidator;
public static function nullOrCreditCard(string $brand = 'Any'): ChainedValidator;
/**
* @param "alpha-3"|"numeric" $set
*/
public static function nullOfCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public static function nullOrCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public static function nullOfDate(string $format = 'Y-m-d'): ChainedValidator;
public static function nullOrDate(string $format = 'Y-m-d'): ChainedValidator;
public static function nullOfDateTime(?string $format = null): ChainedValidator;
public static function nullOrDateTime(?string $format = null): ChainedValidator;
public static function nullOfDecimal(int $decimals): ChainedValidator;
public static function nullOrDecimal(int $decimals): ChainedValidator;
public static function nullOfDigit(string ...$additionalChars): ChainedValidator;
public static function nullOrDigit(string ...$additionalChars): ChainedValidator;
public static function nullOfDirectory(): ChainedValidator;
public static function nullOrDirectory(): ChainedValidator;
public static function nullOfDomain(bool $tldCheck = true): ChainedValidator;
public static function nullOrDomain(bool $tldCheck = true): ChainedValidator;
public static function nullOfEach(Validatable $rule): ChainedValidator;
public static function nullOrEach(Validatable $rule): ChainedValidator;
public static function nullOfEmail(): ChainedValidator;
public static function nullOrEmail(): ChainedValidator;
public static function nullOfEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public static function nullOrEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public static function nullOfEquals(mixed $compareTo): ChainedValidator;
public static function nullOrEquals(mixed $compareTo): ChainedValidator;
public static function nullOfEquivalent(mixed $compareTo): ChainedValidator;
public static function nullOrEquivalent(mixed $compareTo): ChainedValidator;
public static function nullOfEven(): ChainedValidator;
public static function nullOrEven(): ChainedValidator;
public static function nullOfExecutable(): ChainedValidator;
public static function nullOrExecutable(): ChainedValidator;
public static function nullOfExists(): ChainedValidator;
public static function nullOrExists(): ChainedValidator;
public static function nullOfExtension(string $extension): ChainedValidator;
public static function nullOrExtension(string $extension): ChainedValidator;
public static function nullOfFactor(int $dividend): ChainedValidator;
public static function nullOrFactor(int $dividend): ChainedValidator;
public static function nullOfFalseVal(): ChainedValidator;
public static function nullOrFalseVal(): ChainedValidator;
public static function nullOfFibonacci(): ChainedValidator;
public static function nullOrFibonacci(): ChainedValidator;
public static function nullOfFile(): ChainedValidator;
public static function nullOrFile(): ChainedValidator;
public static function nullOfFilterVar(int $filter, mixed $options = null): ChainedValidator;
public static function nullOrFilterVar(int $filter, mixed $options = null): ChainedValidator;
public static function nullOfFinite(): ChainedValidator;
public static function nullOrFinite(): ChainedValidator;
public static function nullOfFloatType(): ChainedValidator;
public static function nullOrFloatType(): ChainedValidator;
public static function nullOfFloatVal(): ChainedValidator;
public static function nullOrFloatVal(): ChainedValidator;
public static function nullOfGraph(string ...$additionalChars): ChainedValidator;
public static function nullOrGraph(string ...$additionalChars): ChainedValidator;
public static function nullOfGreaterThan(mixed $compareTo): ChainedValidator;
public static function nullOrGreaterThan(mixed $compareTo): ChainedValidator;
public static function nullOfGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public static function nullOrGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public static function nullOfHetu(): ChainedValidator;
public static function nullOrHetu(): ChainedValidator;
public static function nullOfHexRgbColor(): ChainedValidator;
public static function nullOrHexRgbColor(): ChainedValidator;
public static function nullOfIban(): ChainedValidator;
public static function nullOrIban(): ChainedValidator;
public static function nullOfIdentical(mixed $compareTo): ChainedValidator;
public static function nullOrIdentical(mixed $compareTo): ChainedValidator;
public static function nullOfImage(): ChainedValidator;
public static function nullOrImage(): ChainedValidator;
public static function nullOfImei(): ChainedValidator;
public static function nullOrImei(): ChainedValidator;
public static function nullOfIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public static function nullOrIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public static function nullOfInfinite(): ChainedValidator;
public static function nullOrInfinite(): ChainedValidator;
/**
* @param class-string $class
*/
public static function nullOfInstance(string $class): ChainedValidator;
public static function nullOrInstance(string $class): ChainedValidator;
public static function nullOfIntType(): ChainedValidator;
public static function nullOrIntType(): ChainedValidator;
public static function nullOfIntVal(): ChainedValidator;
public static function nullOrIntVal(): ChainedValidator;
public static function nullOfIp(string $range = '*', ?int $options = null): ChainedValidator;
public static function nullOrIp(string $range = '*', ?int $options = null): ChainedValidator;
public static function nullOfIsbn(): ChainedValidator;
public static function nullOrIsbn(): ChainedValidator;
public static function nullOfIterableType(): ChainedValidator;
public static function nullOrIterableType(): ChainedValidator;
public static function nullOfIterableVal(): ChainedValidator;
public static function nullOrIterableVal(): ChainedValidator;
public static function nullOfJson(): ChainedValidator;
public static function nullOrJson(): ChainedValidator;
public static function nullOfKey(string|int $key, Validatable $rule): ChainedValidator;
public static function nullOrKey(string|int $key, Validatable $rule): ChainedValidator;
public static function nullOfKeyExists(string|int $key): ChainedValidator;
public static function nullOrKeyExists(string|int $key): ChainedValidator;
public static function nullOfKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public static function nullOrKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public static function nullOfKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
public static function nullOrKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3" $set
*/
public static function nullOfLanguageCode(string $set = 'alpha-2'): ChainedValidator;
public static function nullOrLanguageCode(string $set = 'alpha-2'): ChainedValidator;
/**
* @param callable(mixed): Validatable $ruleCreator
*/
public static function nullOfLazy(callable $ruleCreator): ChainedValidator;
public static function nullOrLazy(callable $ruleCreator): ChainedValidator;
public static function nullOfLeapDate(string $format): ChainedValidator;
public static function nullOrLeapDate(string $format): ChainedValidator;
public static function nullOfLeapYear(): ChainedValidator;
public static function nullOrLeapYear(): ChainedValidator;
public static function nullOfLength(Validatable $rule): ChainedValidator;
public static function nullOrLength(Validatable $rule): ChainedValidator;
public static function nullOfLessThan(mixed $compareTo): ChainedValidator;
public static function nullOrLessThan(mixed $compareTo): ChainedValidator;
public static function nullOfLessThanOrEqual(mixed $compareTo): ChainedValidator;
public static function nullOrLessThanOrEqual(mixed $compareTo): ChainedValidator;
public static function nullOfLowercase(): ChainedValidator;
public static function nullOrLowercase(): ChainedValidator;
public static function nullOfLuhn(): ChainedValidator;
public static function nullOrLuhn(): ChainedValidator;
public static function nullOfMacAddress(): ChainedValidator;
public static function nullOrMacAddress(): ChainedValidator;
public static function nullOfMax(Validatable $rule): ChainedValidator;
public static function nullOrMax(Validatable $rule): ChainedValidator;
public static function nullOfMaxAge(int $age, ?string $format = null): ChainedValidator;
public static function nullOrMaxAge(int $age, ?string $format = null): ChainedValidator;
public static function nullOfMimetype(string $mimetype): ChainedValidator;
public static function nullOrMimetype(string $mimetype): ChainedValidator;
public static function nullOfMin(Validatable $rule): ChainedValidator;
public static function nullOrMin(Validatable $rule): ChainedValidator;
public static function nullOfMinAge(int $age, ?string $format = null): ChainedValidator;
public static function nullOrMinAge(int $age, ?string $format = null): ChainedValidator;
public static function nullOfMultiple(int $multipleOf): ChainedValidator;
public static function nullOrMultiple(int $multipleOf): ChainedValidator;
public static function nullOfNegative(): ChainedValidator;
public static function nullOrNegative(): ChainedValidator;
public static function nullOfNfeAccessKey(): ChainedValidator;
public static function nullOrNfeAccessKey(): ChainedValidator;
public static function nullOfNif(): ChainedValidator;
public static function nullOrNif(): ChainedValidator;
public static function nullOfNip(): ChainedValidator;
public static function nullOrNip(): ChainedValidator;
public static function nullOfNo(bool $useLocale = false): ChainedValidator;
public static function nullOrNo(bool $useLocale = false): ChainedValidator;
public static function nullOfNoWhitespace(): ChainedValidator;
public static function nullOrNoWhitespace(): ChainedValidator;
public static function nullOfNoneOf(
public static function nullOrNoneOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function nullOfNot(Validatable $rule): ChainedValidator;
public static function nullOrNot(Validatable $rule): ChainedValidator;
public static function nullOfNotBlank(): ChainedValidator;
public static function nullOrNotBlank(): ChainedValidator;
public static function nullOfNotEmoji(): ChainedValidator;
public static function nullOrNotEmoji(): ChainedValidator;
public static function nullOfNotEmpty(): ChainedValidator;
public static function nullOrNotEmpty(): ChainedValidator;
public static function nullOfNotOptional(): ChainedValidator;
public static function nullOrNotOptional(): ChainedValidator;
public static function nullOfNullType(): ChainedValidator;
public static function nullOrNullType(): ChainedValidator;
public static function nullOfNumber(): ChainedValidator;
public static function nullOrNumber(): ChainedValidator;
public static function nullOfNumericVal(): ChainedValidator;
public static function nullOrNumericVal(): ChainedValidator;
public static function nullOfObjectType(): ChainedValidator;
public static function nullOrObjectType(): ChainedValidator;
public static function nullOfOdd(): ChainedValidator;
public static function nullOrOdd(): ChainedValidator;
public static function nullOfOneOf(
public static function nullOrOneOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function nullOfPerfectSquare(): ChainedValidator;
public static function nullOrPerfectSquare(): ChainedValidator;
public static function nullOfPesel(): ChainedValidator;
public static function nullOrPesel(): ChainedValidator;
public static function nullOfPhone(?string $countryCode = null): ChainedValidator;
public static function nullOrPhone(?string $countryCode = null): ChainedValidator;
public static function nullOfPhpLabel(): ChainedValidator;
public static function nullOrPhpLabel(): ChainedValidator;
public static function nullOfPis(): ChainedValidator;
public static function nullOrPis(): ChainedValidator;
public static function nullOfPolishIdCard(): ChainedValidator;
public static function nullOrPolishIdCard(): ChainedValidator;
public static function nullOfPortugueseNif(): ChainedValidator;
public static function nullOrPortugueseNif(): ChainedValidator;
public static function nullOfPositive(): ChainedValidator;
public static function nullOrPositive(): ChainedValidator;
public static function nullOfPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public static function nullOrPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public static function nullOfPrimeNumber(): ChainedValidator;
public static function nullOrPrimeNumber(): ChainedValidator;
public static function nullOfPrintable(string ...$additionalChars): ChainedValidator;
public static function nullOrPrintable(string ...$additionalChars): ChainedValidator;
public static function nullOfProperty(string $propertyName, Validatable $rule): ChainedValidator;
public static function nullOrProperty(string $propertyName, Validatable $rule): ChainedValidator;
public static function nullOfPropertyExists(string $propertyName): ChainedValidator;
public static function nullOrPropertyExists(string $propertyName): ChainedValidator;
public static function nullOfPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public static function nullOrPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public static function nullOfPublicDomainSuffix(): ChainedValidator;
public static function nullOrPublicDomainSuffix(): ChainedValidator;
public static function nullOfPunct(string ...$additionalChars): ChainedValidator;
public static function nullOrPunct(string ...$additionalChars): ChainedValidator;
public static function nullOfReadable(): ChainedValidator;
public static function nullOrReadable(): ChainedValidator;
public static function nullOfRegex(string $regex): ChainedValidator;
public static function nullOrRegex(string $regex): ChainedValidator;
public static function nullOfResourceType(): ChainedValidator;
public static function nullOrResourceType(): ChainedValidator;
public static function nullOfRoman(): ChainedValidator;
public static function nullOrRoman(): ChainedValidator;
public static function nullOfScalarVal(): ChainedValidator;
public static function nullOrScalarVal(): ChainedValidator;
public static function nullOfSize(
public static function nullOrSize(
string|int|null $minSize = null,
string|int|null $maxSize = null,
): ChainedValidator;
public static function nullOfSlug(): ChainedValidator;
public static function nullOrSlug(): ChainedValidator;
public static function nullOfSorted(string $direction): ChainedValidator;
public static function nullOrSorted(string $direction): ChainedValidator;
public static function nullOfSpace(string ...$additionalChars): ChainedValidator;
public static function nullOrSpace(string ...$additionalChars): ChainedValidator;
public static function nullOfStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public static function nullOrStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public static function nullOfStringType(): ChainedValidator;
public static function nullOrStringType(): ChainedValidator;
public static function nullOfStringVal(): ChainedValidator;
public static function nullOrStringVal(): ChainedValidator;
public static function nullOfSubdivisionCode(string $countryCode): ChainedValidator;
public static function nullOrSubdivisionCode(string $countryCode): ChainedValidator;
/**
* @param mixed[] $superset
*/
public static function nullOfSubset(array $superset): ChainedValidator;
public static function nullOrSubset(array $superset): ChainedValidator;
public static function nullOfSymbolicLink(): ChainedValidator;
public static function nullOrSymbolicLink(): ChainedValidator;
public static function nullOfTime(string $format = 'H:i:s'): ChainedValidator;
public static function nullOrTime(string $format = 'H:i:s'): ChainedValidator;
public static function nullOfTld(): ChainedValidator;
public static function nullOrTld(): ChainedValidator;
public static function nullOfTrueVal(): ChainedValidator;
public static function nullOrTrueVal(): ChainedValidator;
public static function nullOfUnique(): ChainedValidator;
public static function nullOrUnique(): ChainedValidator;
public static function nullOfUploaded(): ChainedValidator;
public static function nullOrUploaded(): ChainedValidator;
public static function nullOfUppercase(): ChainedValidator;
public static function nullOrUppercase(): ChainedValidator;
public static function nullOfUrl(): ChainedValidator;
public static function nullOrUrl(): ChainedValidator;
public static function nullOfUuid(?int $version = null): ChainedValidator;
public static function nullOrUuid(?int $version = null): ChainedValidator;
public static function nullOfVersion(): ChainedValidator;
public static function nullOrVersion(): ChainedValidator;
public static function nullOfVideoUrl(?string $service = null): ChainedValidator;
public static function nullOrVideoUrl(?string $service = null): ChainedValidator;
public static function nullOfVowel(string ...$additionalChars): ChainedValidator;
public static function nullOrVowel(string ...$additionalChars): ChainedValidator;
public static function nullOfWhen(
public static function nullOrWhen(
Validatable $when,
Validatable $then,
?Validatable $else = null,
): ChainedValidator;
public static function nullOfWritable(): ChainedValidator;
public static function nullOrWritable(): ChainedValidator;
public static function nullOfXdigit(string ...$additionalChars): ChainedValidator;
public static function nullOrXdigit(string ...$additionalChars): ChainedValidator;
public static function nullOfYes(bool $useLocale = false): ChainedValidator;
public static function nullOrYes(bool $useLocale = false): ChainedValidator;
}

View file

@ -293,8 +293,6 @@ interface StaticProperty
public static function propertyNullType(string $propertyName): ChainedValidator;
public static function propertyNullable(string $propertyName, Validatable $rule): ChainedValidator;
public static function propertyNumber(string $propertyName): ChainedValidator;
public static function propertyNumericVal(string $propertyName): ChainedValidator;
@ -310,8 +308,6 @@ interface StaticProperty
Validatable ...$rules,
): ChainedValidator;
public static function propertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public static function propertyPerfectSquare(string $propertyName): ChainedValidator;
public static function propertyPesel(string $propertyName): ChainedValidator;

View file

@ -13,368 +13,368 @@ use Respect\Validation\Validatable;
interface StaticUndefOr
{
public static function undefOfAllOf(
public static function undefOrAllOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function undefOfAlnum(string ...$additionalChars): ChainedValidator;
public static function undefOrAlnum(string ...$additionalChars): ChainedValidator;
public static function undefOfAlpha(string ...$additionalChars): ChainedValidator;
public static function undefOrAlpha(string ...$additionalChars): ChainedValidator;
public static function undefOfAlwaysInvalid(): ChainedValidator;
public static function undefOrAlwaysInvalid(): ChainedValidator;
public static function undefOfAlwaysValid(): ChainedValidator;
public static function undefOrAlwaysValid(): ChainedValidator;
public static function undefOfAnyOf(
public static function undefOrAnyOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function undefOfArrayType(): ChainedValidator;
public static function undefOrArrayType(): ChainedValidator;
public static function undefOfArrayVal(): ChainedValidator;
public static function undefOrArrayVal(): ChainedValidator;
public static function undefOfBase(
public static function undefOrBase(
int $base,
string $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
): ChainedValidator;
public static function undefOfBase64(): ChainedValidator;
public static function undefOrBase64(): ChainedValidator;
public static function undefOfBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public static function undefOrBetween(mixed $minValue, mixed $maxValue): ChainedValidator;
public static function undefOfBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public static function undefOrBetweenExclusive(mixed $minimum, mixed $maximum): ChainedValidator;
public static function undefOfBoolType(): ChainedValidator;
public static function undefOrBoolType(): ChainedValidator;
public static function undefOfBoolVal(): ChainedValidator;
public static function undefOrBoolVal(): ChainedValidator;
public static function undefOfBsn(): ChainedValidator;
public static function undefOrBsn(): ChainedValidator;
public static function undefOfCall(callable $callable, Validatable $rule): ChainedValidator;
public static function undefOrCall(callable $callable, Validatable $rule): ChainedValidator;
public static function undefOfCallableType(): ChainedValidator;
public static function undefOrCallableType(): ChainedValidator;
public static function undefOfCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public static function undefOrCallback(callable $callback, mixed ...$arguments): ChainedValidator;
public static function undefOfCharset(string $charset, string ...$charsets): ChainedValidator;
public static function undefOrCharset(string $charset, string ...$charsets): ChainedValidator;
public static function undefOfCnh(): ChainedValidator;
public static function undefOrCnh(): ChainedValidator;
public static function undefOfCnpj(): ChainedValidator;
public static function undefOrCnpj(): ChainedValidator;
public static function undefOfConsecutive(
public static function undefOrConsecutive(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function undefOfConsonant(string ...$additionalChars): ChainedValidator;
public static function undefOrConsonant(string ...$additionalChars): ChainedValidator;
public static function undefOfContains(mixed $containsValue, bool $identical = false): ChainedValidator;
public static function undefOrContains(mixed $containsValue, bool $identical = false): ChainedValidator;
/**
* @param non-empty-array<mixed> $needles
*/
public static function undefOfContainsAny(array $needles, bool $identical = false): ChainedValidator;
public static function undefOrContainsAny(array $needles, bool $identical = false): ChainedValidator;
public static function undefOfControl(string ...$additionalChars): ChainedValidator;
public static function undefOrControl(string ...$additionalChars): ChainedValidator;
public static function undefOfCountable(): ChainedValidator;
public static function undefOrCountable(): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3"|"numeric" $set
*/
public static function undefOfCountryCode(string $set = 'alpha-2'): ChainedValidator;
public static function undefOrCountryCode(string $set = 'alpha-2'): ChainedValidator;
public static function undefOfCpf(): ChainedValidator;
public static function undefOrCpf(): ChainedValidator;
public static function undefOfCreditCard(string $brand = 'Any'): ChainedValidator;
public static function undefOrCreditCard(string $brand = 'Any'): ChainedValidator;
/**
* @param "alpha-3"|"numeric" $set
*/
public static function undefOfCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public static function undefOrCurrencyCode(string $set = 'alpha-3'): ChainedValidator;
public static function undefOfDate(string $format = 'Y-m-d'): ChainedValidator;
public static function undefOrDate(string $format = 'Y-m-d'): ChainedValidator;
public static function undefOfDateTime(?string $format = null): ChainedValidator;
public static function undefOrDateTime(?string $format = null): ChainedValidator;
public static function undefOfDecimal(int $decimals): ChainedValidator;
public static function undefOrDecimal(int $decimals): ChainedValidator;
public static function undefOfDigit(string ...$additionalChars): ChainedValidator;
public static function undefOrDigit(string ...$additionalChars): ChainedValidator;
public static function undefOfDirectory(): ChainedValidator;
public static function undefOrDirectory(): ChainedValidator;
public static function undefOfDomain(bool $tldCheck = true): ChainedValidator;
public static function undefOrDomain(bool $tldCheck = true): ChainedValidator;
public static function undefOfEach(Validatable $rule): ChainedValidator;
public static function undefOrEach(Validatable $rule): ChainedValidator;
public static function undefOfEmail(): ChainedValidator;
public static function undefOrEmail(): ChainedValidator;
public static function undefOfEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public static function undefOrEndsWith(mixed $endValue, bool $identical = false): ChainedValidator;
public static function undefOfEquals(mixed $compareTo): ChainedValidator;
public static function undefOrEquals(mixed $compareTo): ChainedValidator;
public static function undefOfEquivalent(mixed $compareTo): ChainedValidator;
public static function undefOrEquivalent(mixed $compareTo): ChainedValidator;
public static function undefOfEven(): ChainedValidator;
public static function undefOrEven(): ChainedValidator;
public static function undefOfExecutable(): ChainedValidator;
public static function undefOrExecutable(): ChainedValidator;
public static function undefOfExists(): ChainedValidator;
public static function undefOrExists(): ChainedValidator;
public static function undefOfExtension(string $extension): ChainedValidator;
public static function undefOrExtension(string $extension): ChainedValidator;
public static function undefOfFactor(int $dividend): ChainedValidator;
public static function undefOrFactor(int $dividend): ChainedValidator;
public static function undefOfFalseVal(): ChainedValidator;
public static function undefOrFalseVal(): ChainedValidator;
public static function undefOfFibonacci(): ChainedValidator;
public static function undefOrFibonacci(): ChainedValidator;
public static function undefOfFile(): ChainedValidator;
public static function undefOrFile(): ChainedValidator;
public static function undefOfFilterVar(int $filter, mixed $options = null): ChainedValidator;
public static function undefOrFilterVar(int $filter, mixed $options = null): ChainedValidator;
public static function undefOfFinite(): ChainedValidator;
public static function undefOrFinite(): ChainedValidator;
public static function undefOfFloatType(): ChainedValidator;
public static function undefOrFloatType(): ChainedValidator;
public static function undefOfFloatVal(): ChainedValidator;
public static function undefOrFloatVal(): ChainedValidator;
public static function undefOfGraph(string ...$additionalChars): ChainedValidator;
public static function undefOrGraph(string ...$additionalChars): ChainedValidator;
public static function undefOfGreaterThan(mixed $compareTo): ChainedValidator;
public static function undefOrGreaterThan(mixed $compareTo): ChainedValidator;
public static function undefOfGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public static function undefOrGreaterThanOrEqual(mixed $compareTo): ChainedValidator;
public static function undefOfHetu(): ChainedValidator;
public static function undefOrHetu(): ChainedValidator;
public static function undefOfHexRgbColor(): ChainedValidator;
public static function undefOrHexRgbColor(): ChainedValidator;
public static function undefOfIban(): ChainedValidator;
public static function undefOrIban(): ChainedValidator;
public static function undefOfIdentical(mixed $compareTo): ChainedValidator;
public static function undefOrIdentical(mixed $compareTo): ChainedValidator;
public static function undefOfImage(): ChainedValidator;
public static function undefOrImage(): ChainedValidator;
public static function undefOfImei(): ChainedValidator;
public static function undefOrImei(): ChainedValidator;
public static function undefOfIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public static function undefOrIn(mixed $haystack, bool $compareIdentical = false): ChainedValidator;
public static function undefOfInfinite(): ChainedValidator;
public static function undefOrInfinite(): ChainedValidator;
/**
* @param class-string $class
*/
public static function undefOfInstance(string $class): ChainedValidator;
public static function undefOrInstance(string $class): ChainedValidator;
public static function undefOfIntType(): ChainedValidator;
public static function undefOrIntType(): ChainedValidator;
public static function undefOfIntVal(): ChainedValidator;
public static function undefOrIntVal(): ChainedValidator;
public static function undefOfIp(string $range = '*', ?int $options = null): ChainedValidator;
public static function undefOrIp(string $range = '*', ?int $options = null): ChainedValidator;
public static function undefOfIsbn(): ChainedValidator;
public static function undefOrIsbn(): ChainedValidator;
public static function undefOfIterableType(): ChainedValidator;
public static function undefOrIterableType(): ChainedValidator;
public static function undefOfIterableVal(): ChainedValidator;
public static function undefOrIterableVal(): ChainedValidator;
public static function undefOfJson(): ChainedValidator;
public static function undefOrJson(): ChainedValidator;
public static function undefOfKey(string|int $key, Validatable $rule): ChainedValidator;
public static function undefOrKey(string|int $key, Validatable $rule): ChainedValidator;
public static function undefOfKeyExists(string|int $key): ChainedValidator;
public static function undefOrKeyExists(string|int $key): ChainedValidator;
public static function undefOfKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public static function undefOrKeyOptional(string|int $key, Validatable $rule): ChainedValidator;
public static function undefOfKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
public static function undefOrKeySet(Validatable $rule, Validatable ...$rules): ChainedValidator;
/**
* @param "alpha-2"|"alpha-3" $set
*/
public static function undefOfLanguageCode(string $set = 'alpha-2'): ChainedValidator;
public static function undefOrLanguageCode(string $set = 'alpha-2'): ChainedValidator;
/**
* @param callable(mixed): Validatable $ruleCreator
*/
public static function undefOfLazy(callable $ruleCreator): ChainedValidator;
public static function undefOrLazy(callable $ruleCreator): ChainedValidator;
public static function undefOfLeapDate(string $format): ChainedValidator;
public static function undefOrLeapDate(string $format): ChainedValidator;
public static function undefOfLeapYear(): ChainedValidator;
public static function undefOrLeapYear(): ChainedValidator;
public static function undefOfLength(Validatable $rule): ChainedValidator;
public static function undefOrLength(Validatable $rule): ChainedValidator;
public static function undefOfLessThan(mixed $compareTo): ChainedValidator;
public static function undefOrLessThan(mixed $compareTo): ChainedValidator;
public static function undefOfLessThanOrEqual(mixed $compareTo): ChainedValidator;
public static function undefOrLessThanOrEqual(mixed $compareTo): ChainedValidator;
public static function undefOfLowercase(): ChainedValidator;
public static function undefOrLowercase(): ChainedValidator;
public static function undefOfLuhn(): ChainedValidator;
public static function undefOrLuhn(): ChainedValidator;
public static function undefOfMacAddress(): ChainedValidator;
public static function undefOrMacAddress(): ChainedValidator;
public static function undefOfMax(Validatable $rule): ChainedValidator;
public static function undefOrMax(Validatable $rule): ChainedValidator;
public static function undefOfMaxAge(int $age, ?string $format = null): ChainedValidator;
public static function undefOrMaxAge(int $age, ?string $format = null): ChainedValidator;
public static function undefOfMimetype(string $mimetype): ChainedValidator;
public static function undefOrMimetype(string $mimetype): ChainedValidator;
public static function undefOfMin(Validatable $rule): ChainedValidator;
public static function undefOrMin(Validatable $rule): ChainedValidator;
public static function undefOfMinAge(int $age, ?string $format = null): ChainedValidator;
public static function undefOrMinAge(int $age, ?string $format = null): ChainedValidator;
public static function undefOfMultiple(int $multipleOf): ChainedValidator;
public static function undefOrMultiple(int $multipleOf): ChainedValidator;
public static function undefOfNegative(): ChainedValidator;
public static function undefOrNegative(): ChainedValidator;
public static function undefOfNfeAccessKey(): ChainedValidator;
public static function undefOrNfeAccessKey(): ChainedValidator;
public static function undefOfNif(): ChainedValidator;
public static function undefOrNif(): ChainedValidator;
public static function undefOfNip(): ChainedValidator;
public static function undefOrNip(): ChainedValidator;
public static function undefOfNo(bool $useLocale = false): ChainedValidator;
public static function undefOrNo(bool $useLocale = false): ChainedValidator;
public static function undefOfNoWhitespace(): ChainedValidator;
public static function undefOrNoWhitespace(): ChainedValidator;
public static function undefOfNoneOf(
public static function undefOrNoneOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function undefOfNot(Validatable $rule): ChainedValidator;
public static function undefOrNot(Validatable $rule): ChainedValidator;
public static function undefOfNotBlank(): ChainedValidator;
public static function undefOrNotBlank(): ChainedValidator;
public static function undefOfNotEmoji(): ChainedValidator;
public static function undefOrNotEmoji(): ChainedValidator;
public static function undefOfNotEmpty(): ChainedValidator;
public static function undefOrNotEmpty(): ChainedValidator;
public static function undefOfNotOptional(): ChainedValidator;
public static function undefOrNotOptional(): ChainedValidator;
public static function undefOfNullType(): ChainedValidator;
public static function undefOrNullType(): ChainedValidator;
public static function undefOfNumber(): ChainedValidator;
public static function undefOrNumber(): ChainedValidator;
public static function undefOfNumericVal(): ChainedValidator;
public static function undefOrNumericVal(): ChainedValidator;
public static function undefOfObjectType(): ChainedValidator;
public static function undefOrObjectType(): ChainedValidator;
public static function undefOfOdd(): ChainedValidator;
public static function undefOrOdd(): ChainedValidator;
public static function undefOfOneOf(
public static function undefOrOneOf(
Validatable $rule1,
Validatable $rule2,
Validatable ...$rules,
): ChainedValidator;
public static function undefOfPerfectSquare(): ChainedValidator;
public static function undefOrPerfectSquare(): ChainedValidator;
public static function undefOfPesel(): ChainedValidator;
public static function undefOrPesel(): ChainedValidator;
public static function undefOfPhone(?string $countryCode = null): ChainedValidator;
public static function undefOrPhone(?string $countryCode = null): ChainedValidator;
public static function undefOfPhpLabel(): ChainedValidator;
public static function undefOrPhpLabel(): ChainedValidator;
public static function undefOfPis(): ChainedValidator;
public static function undefOrPis(): ChainedValidator;
public static function undefOfPolishIdCard(): ChainedValidator;
public static function undefOrPolishIdCard(): ChainedValidator;
public static function undefOfPortugueseNif(): ChainedValidator;
public static function undefOrPortugueseNif(): ChainedValidator;
public static function undefOfPositive(): ChainedValidator;
public static function undefOrPositive(): ChainedValidator;
public static function undefOfPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public static function undefOrPostalCode(string $countryCode, bool $formatted = false): ChainedValidator;
public static function undefOfPrimeNumber(): ChainedValidator;
public static function undefOrPrimeNumber(): ChainedValidator;
public static function undefOfPrintable(string ...$additionalChars): ChainedValidator;
public static function undefOrPrintable(string ...$additionalChars): ChainedValidator;
public static function undefOfProperty(string $propertyName, Validatable $rule): ChainedValidator;
public static function undefOrProperty(string $propertyName, Validatable $rule): ChainedValidator;
public static function undefOfPropertyExists(string $propertyName): ChainedValidator;
public static function undefOrPropertyExists(string $propertyName): ChainedValidator;
public static function undefOfPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public static function undefOrPropertyOptional(string $propertyName, Validatable $rule): ChainedValidator;
public static function undefOfPublicDomainSuffix(): ChainedValidator;
public static function undefOrPublicDomainSuffix(): ChainedValidator;
public static function undefOfPunct(string ...$additionalChars): ChainedValidator;
public static function undefOrPunct(string ...$additionalChars): ChainedValidator;
public static function undefOfReadable(): ChainedValidator;
public static function undefOrReadable(): ChainedValidator;
public static function undefOfRegex(string $regex): ChainedValidator;
public static function undefOrRegex(string $regex): ChainedValidator;
public static function undefOfResourceType(): ChainedValidator;
public static function undefOrResourceType(): ChainedValidator;
public static function undefOfRoman(): ChainedValidator;
public static function undefOrRoman(): ChainedValidator;
public static function undefOfScalarVal(): ChainedValidator;
public static function undefOrScalarVal(): ChainedValidator;
public static function undefOfSize(
public static function undefOrSize(
string|int|null $minSize = null,
string|int|null $maxSize = null,
): ChainedValidator;
public static function undefOfSlug(): ChainedValidator;
public static function undefOrSlug(): ChainedValidator;
public static function undefOfSorted(string $direction): ChainedValidator;
public static function undefOrSorted(string $direction): ChainedValidator;
public static function undefOfSpace(string ...$additionalChars): ChainedValidator;
public static function undefOrSpace(string ...$additionalChars): ChainedValidator;
public static function undefOfStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public static function undefOrStartsWith(mixed $startValue, bool $identical = false): ChainedValidator;
public static function undefOfStringType(): ChainedValidator;
public static function undefOrStringType(): ChainedValidator;
public static function undefOfStringVal(): ChainedValidator;
public static function undefOrStringVal(): ChainedValidator;
public static function undefOfSubdivisionCode(string $countryCode): ChainedValidator;
public static function undefOrSubdivisionCode(string $countryCode): ChainedValidator;
/**
* @param mixed[] $superset
*/
public static function undefOfSubset(array $superset): ChainedValidator;
public static function undefOrSubset(array $superset): ChainedValidator;
public static function undefOfSymbolicLink(): ChainedValidator;
public static function undefOrSymbolicLink(): ChainedValidator;
public static function undefOfTime(string $format = 'H:i:s'): ChainedValidator;
public static function undefOrTime(string $format = 'H:i:s'): ChainedValidator;
public static function undefOfTld(): ChainedValidator;
public static function undefOrTld(): ChainedValidator;
public static function undefOfTrueVal(): ChainedValidator;
public static function undefOrTrueVal(): ChainedValidator;
public static function undefOfUnique(): ChainedValidator;
public static function undefOrUnique(): ChainedValidator;
public static function undefOfUploaded(): ChainedValidator;
public static function undefOrUploaded(): ChainedValidator;
public static function undefOfUppercase(): ChainedValidator;
public static function undefOrUppercase(): ChainedValidator;
public static function undefOfUrl(): ChainedValidator;
public static function undefOrUrl(): ChainedValidator;
public static function undefOfUuid(?int $version = null): ChainedValidator;
public static function undefOrUuid(?int $version = null): ChainedValidator;
public static function undefOfVersion(): ChainedValidator;
public static function undefOrVersion(): ChainedValidator;
public static function undefOfVideoUrl(?string $service = null): ChainedValidator;
public static function undefOrVideoUrl(?string $service = null): ChainedValidator;
public static function undefOfVowel(string ...$additionalChars): ChainedValidator;
public static function undefOrVowel(string ...$additionalChars): ChainedValidator;
public static function undefOfWhen(
public static function undefOrWhen(
Validatable $when,
Validatable $then,
?Validatable $else = null,
): ChainedValidator;
public static function undefOfWritable(): ChainedValidator;
public static function undefOrWritable(): ChainedValidator;
public static function undefOfXdigit(string ...$additionalChars): ChainedValidator;
public static function undefOrXdigit(string ...$additionalChars): ChainedValidator;
public static function undefOfYes(bool $useLocale = false): ChainedValidator;
public static function undefOrYes(bool $useLocale = false): ChainedValidator;
}

View file

@ -256,8 +256,13 @@ interface StaticValidator extends
public static function notOptional(): ChainedValidator;
public static function nullOr(Validatable $rule): ChainedValidator;
public static function nullType(): ChainedValidator;
/**
* @deprecated Use {@see nullOr()} instead.
*/
public static function nullable(Validatable $rule): ChainedValidator;
public static function number(): ChainedValidator;
@ -270,6 +275,9 @@ interface StaticValidator extends
public static function oneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rules): ChainedValidator;
/**
* @deprecated Use {@see undefOr()} instead.
*/
public static function optional(Validatable $rule): ChainedValidator;
public static function perfectSquare(): ChainedValidator;
@ -343,6 +351,8 @@ interface StaticValidator extends
public static function trueVal(): ChainedValidator;
public static function undefOr(Validatable $rule): ChainedValidator;
public static function unique(): ChainedValidator;
public static function uploaded(): ChainedValidator;

View file

@ -16,6 +16,7 @@ use function lcfirst;
use function preg_match;
use function strrchr;
use function substr;
use function ucfirst;
final class Result
{
@ -43,7 +44,7 @@ final class Result
) {
$this->name = $rule->getName() ?? $name;
$this->template = $rule->getTemplate() ?? $template;
$this->id = $id ?? $this->name ?? lcfirst(substr((string) strrchr($rule::class, '\\'), 1));
$this->id = $id ?? lcfirst(substr((string) strrchr($rule::class, '\\'), 1));
$this->children = $children;
}
@ -77,6 +78,15 @@ final class Result
return $this->clone(id: $id);
}
public function withPrefixedId(string $prefix): self
{
if ($this->id === $this->name) {
return $this;
}
return $this->clone(id: $prefix . ucfirst($this->id));
}
public function withChildren(Result ...$children): self
{
return $this->clone(children: $children);

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Standard;
@ -17,7 +17,6 @@ use Respect\Validation\Rules\Core\Standard;
use function mb_strlen;
use function mb_substr;
use function preg_match;
use function sprintf;
#[Template(
'{{name}} must be a number in the base {{base|raw}}',
@ -31,7 +30,7 @@ final class Base extends Standard
) {
$max = mb_strlen($this->chars);
if ($base > $max) {
throw new ComponentException(sprintf('a base between 1 and %s is required', $max));
throw new InvalidRuleConstructorException('a base between 1 and %s is required', (string) $max);
}
}

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Helpers\CanCompareValues;
use Respect\Validation\Message\Template;
use Respect\Validation\Rules\Core\Envelope;
@ -25,7 +25,7 @@ final class Between extends Envelope
public function __construct(mixed $minValue, mixed $maxValue)
{
if ($this->toComparable($minValue) >= $this->toComparable($maxValue)) {
throw new ComponentException('Minimum cannot be less than or equals to maximum');
throw new InvalidRuleConstructorException('Minimum cannot be less than or equals to maximum');
}
parent::__construct(

View file

@ -15,7 +15,6 @@ use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Standard;
use function array_keys;
use function implode;
use function is_scalar;
use function preg_match;
use function preg_replace;
@ -60,7 +59,7 @@ final class CreditCard extends Standard
throw new InvalidRuleConstructorException(
'"%s" is not a valid credit card brand (Available: %s)',
$brand,
implode(', ', array_keys(self::BRAND_REGEX_LIST))
array_keys(self::BRAND_REGEX_LIST)
);
}
}

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Helpers\CanValidateDateTime;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
@ -18,7 +18,6 @@ use Respect\Validation\Rules\Core\Standard;
use function date;
use function is_scalar;
use function preg_match;
use function sprintf;
use function strtotime;
#[Template(
@ -33,7 +32,7 @@ final class Date extends Standard
private readonly string $format = 'Y-m-d'
) {
if (!preg_match('/^[djSFmMnYy\W]+$/', $format)) {
throw new ComponentException(sprintf('"%s" is not a valid date format', $format));
throw new InvalidRuleConstructorException('"%s" is not a valid date format', $format);
}
}

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Message\Template;
use Respect\Validation\Rules\Core\Envelope;
@ -47,7 +47,7 @@ final class FilterVar extends Envelope
public function __construct(int $filter, mixed $options = null)
{
if (!array_key_exists($filter, self::ALLOWED_FILTERS)) {
throw new ComponentException('Cannot accept the given filter');
throw new InvalidRuleConstructorException('Cannot accept the given filter');
}
$arguments = [$filter];

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Standard;
@ -103,11 +103,11 @@ final class Ip extends Standard
[$this->startAddress, $this->endAddress] = explode('-', $input);
if ($this->startAddress !== null && !$this->verifyAddress($this->startAddress)) {
throw new ComponentException('Invalid network range');
throw new InvalidRuleConstructorException('Invalid network range');
}
if ($this->endAddress !== null && !$this->verifyAddress($this->endAddress)) {
throw new ComponentException('Invalid network range');
throw new InvalidRuleConstructorException('Invalid network range');
}
return;
@ -125,7 +125,7 @@ final class Ip extends Standard
return;
}
throw new ComponentException('Invalid network range');
throw new InvalidRuleConstructorException('Invalid network range');
}
private function fillAddress(string $address, string $fill = '*'): string
@ -155,7 +155,7 @@ final class Ip extends Standard
}
if ($isAddressMask || $parts[1] < 8 || $parts[1] > 30) {
throw new ComponentException('Invalid network mask');
throw new InvalidRuleConstructorException('Invalid network mask');
}
$this->mask = sprintf('%032b', ip2long((string) long2ip(~(2 ** (32 - (int) $parts[1]) - 1))));

View file

@ -38,10 +38,13 @@ final class Key extends Wrapper
return $keyExistsResult;
}
$child = $this->rule->evaluate($input[$this->key]);
$child = $this->rule
->evaluate($input[$this->key])
->withId((string) $this->key);
return (new Result($child->isValid, $input, $this))
->withChildren($child)
->withId((string) $this->key)
->withNameIfMissing($this->rule->getName() ?? (string) $this->key);
}
}

View file

@ -30,7 +30,7 @@ final class KeyExists extends Standard
public function evaluate(mixed $input): Result
{
return new Result($this->hasKey($input), $input, $this, name: (string) $this->key);
return new Result($this->hasKey($input), $input, $this, name: (string) $this->key, id: (string) $this->key);
}
private function hasKey(mixed $input): bool

View file

@ -33,10 +33,13 @@ final class KeyOptional extends Wrapper
return $keyExistsResult->withInvertedMode();
}
$child = $this->rule->evaluate($input[$this->key]);
$child = $this->rule
->evaluate($input[$this->key])
->withId((string) $this->key);
return (new Result($child->isValid, $input, $this))
->withChildren($child)
->withId((string) $this->key)
->withNameIfMissing($this->rule->getName() ?? (string) $this->key);
}
}

View file

@ -18,6 +18,7 @@ use Respect\Validation\Rules\Core\Wrapper;
use function count;
use function is_string;
use function mb_strlen;
use function ucfirst;
#[Template('The length of', 'The length of')]
final class Length extends Wrapper
@ -28,12 +29,14 @@ final class Length extends Wrapper
{
$typeResult = $this->bindEvaluate(new OneOf(new StringType(), new Countable()), $this, $input);
if (!$typeResult->isValid) {
return Result::failed($input, $this)->withNextSibling($this->rule->evaluate($input));
$result = $this->rule->evaluate($input);
return Result::failed($input, $this)->withNextSibling($result)->withId('length' . ucfirst($result->id));
}
$result = $this->rule->evaluate($this->extractLength($input))->withInput($input);
$result = $this->rule->evaluate($this->extractLength($input))->withInput($input)->withPrefixedId('length');
return (new Result($result->isValid, $input, $this))->withNextSibling($result);
return (new Result($result->isValid, $input, $this, id: $result->id))->withNextSibling($result);
}
/** @param array<mixed>|PhpCountable|string $input */

View file

@ -24,9 +24,9 @@ final class Max extends FilteredNonEmptyArray
/** @param non-empty-array<mixed> $input */
protected function evaluateNonEmptyArray(array $input): Result
{
$result = $this->rule->evaluate(max($input));
$result = $this->rule->evaluate(max($input))->withPrefixedId('max');
$template = $this->getName() === null ? self::TEMPLATE_STANDARD : self::TEMPLATE_NAMED;
return (new Result($result->isValid, $input, $this, [], $template))->withNextSibling($result);
return (new Result($result->isValid, $input, $this, [], $template, id: $result->id))->withNextSibling($result);
}
}

View file

@ -24,9 +24,9 @@ final class Min extends FilteredNonEmptyArray
/** @param non-empty-array<mixed> $input */
protected function evaluateNonEmptyArray(array $input): Result
{
$result = $this->rule->evaluate(min($input));
$result = $this->rule->evaluate(min($input))->withPrefixedId('min');
$template = $this->getName() === null ? self::TEMPLATE_STANDARD : self::TEMPLATE_NAMED;
return (new Result($result->isValid, $input, $this, [], $template))->withNextSibling($result);
return (new Result($result->isValid, $input, $this, [], $template, id: $result->id))->withNextSibling($result);
}
}

View file

@ -16,6 +16,6 @@ final class Not extends Wrapper
{
public function evaluate(mixed $input): Result
{
return parent::evaluate($input)->withInvertedMode();
return $this->rule->evaluate($input)->withInvertedMode()->withPrefixedId('not');
}
}

View file

@ -14,23 +14,23 @@ use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Wrapper;
#[Template(
'The value must be nullable',
'The value must be null',
'The value must not be null',
self::TEMPLATE_STANDARD,
)]
#[Template(
'{{name}} must be nullable',
'{{name}} must be null',
'{{name}} must not be null',
self::TEMPLATE_NAMED,
)]
final class Nullable extends Wrapper
final class NullOr extends Wrapper
{
public const TEMPLATE_NAMED = '__named__';
public function evaluate(mixed $input): Result
{
if ($input !== null) {
return parent::evaluate($input);
return $this->rule->evaluate($input)->withPrefixedId('nullOr');
}
if ($this->getName()) {

View file

@ -9,12 +9,10 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Message\Template;
use Respect\Validation\Rules\Core\Envelope;
use function sprintf;
/**
* @see http://download.geonames.org/export/dump/countryInfo.txt
*/
@ -211,7 +209,7 @@ final class PostalCode extends Envelope
{
$countryCodeRule = new CountryCode();
if (!$countryCodeRule->evaluate($countryCode)->isValid) {
throw new ComponentException(sprintf('Cannot validate postal code from "%s" country', $countryCode));
throw new InvalidRuleConstructorException('Cannot validate postal code from "%s" country', $countryCode);
}
parent::__construct(

View file

@ -35,10 +35,13 @@ final class Property extends Wrapper
return $propertyExistsResult;
}
$childResult = $this->rule->evaluate($this->extractPropertyValue($input, $this->propertyName));
$childResult = $this->rule
->evaluate($this->extractPropertyValue($input, $this->propertyName))
->withId($this->propertyName);
return (new Result($childResult->isValid, $input, $this))
->withChildren($childResult)
->withId($this->propertyName)
->withNameIfMissing($this->rule->getName() ?? $this->propertyName);
}
}

View file

@ -30,11 +30,17 @@ final class PropertyExists extends Standard
public function evaluate(mixed $input): Result
{
if (!is_object($input)) {
return Result::failed($input, $this)->withNameIfMissing($this->propertyName);
return Result::failed($input, $this)->withNameIfMissing($this->propertyName)->withId($this->propertyName);
}
$reflection = new ReflectionObject($input);
return new Result($reflection->hasProperty($this->propertyName), $input, $this, name: $this->propertyName);
return new Result(
$reflection->hasProperty($this->propertyName),
$input,
$this,
name: $this->propertyName,
id: $this->propertyName
);
}
}

View file

@ -35,10 +35,13 @@ final class PropertyOptional extends Wrapper
return $propertyExistsResult->withInvertedMode();
}
$childResult = $this->rule->evaluate($this->extractPropertyValue($input, $this->propertyName));
$childResult = $this->rule
->evaluate($this->extractPropertyValue($input, $this->propertyName))
->withId($this->propertyName);
return (new Result($childResult->isValid, $input, $this))
->withChildren($childResult)
->withId($this->propertyName)
->withNameIfMissing($this->rule->getName() ?? $this->propertyName);
}
}

View file

@ -11,7 +11,7 @@ namespace Respect\Validation\Rules;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Standard;
@ -22,7 +22,6 @@ use function floatval;
use function is_numeric;
use function is_string;
use function preg_match;
use function sprintf;
#[Template(
'{{name}} must be between {{minSize}} and {{maxSize}}',
@ -118,7 +117,7 @@ final class Size extends Standard
}
if (!is_numeric($value)) {
throw new ComponentException(sprintf('"%s" is not a recognized file size.', $size));
throw new InvalidRuleConstructorException('"%s" is not a recognized file size.', $size);
}
return (float) $value;

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Standard;
@ -18,7 +18,6 @@ use function array_values;
use function count;
use function is_array;
use function is_string;
use function sprintf;
use function str_split;
#[Template(
@ -43,8 +42,10 @@ final class Sorted extends Standard
private readonly string $direction
) {
if ($direction !== self::ASCENDING && $direction !== self::DESCENDING) {
throw new ComponentException(
sprintf('Direction should be either "%s" or "%s"', self::ASCENDING, self::DESCENDING)
throw new InvalidRuleConstructorException(
'Direction should be either "%s" or "%s"',
self::ASCENDING,
self::DESCENDING
);
}
}

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Helpers\CanValidateDateTime;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
@ -18,7 +18,6 @@ use Respect\Validation\Rules\Core\Standard;
use function date;
use function is_scalar;
use function preg_match;
use function sprintf;
use function strtotime;
#[Template(
@ -33,7 +32,7 @@ final class Time extends Standard
private readonly string $format = 'H:i:s'
) {
if (!preg_match('/^[gGhHisuvaA\W]+$/', $format)) {
throw new ComponentException(sprintf('"%s" is not a valid date format', $format));
throw new InvalidRuleConstructorException('"%s" is not a valid date format', $format);
}
}

View file

@ -15,16 +15,16 @@ use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Wrapper;
#[Template(
'The value must be optional',
'The value must not be optional',
'The value must be undefined',
'The value must not be undefined',
self::TEMPLATE_STANDARD,
)]
#[Template(
'{{name}} must be optional',
'{{name}} must not be optional',
'{{name}} must be undefined',
'{{name}} must not be undefined',
self::TEMPLATE_NAMED,
)]
final class Optional extends Wrapper
final class UndefOr extends Wrapper
{
use CanValidateUndefined;
@ -33,7 +33,7 @@ final class Optional extends Wrapper
public function evaluate(mixed $input): Result
{
if (!$this->isUndefined($input)) {
return parent::evaluate($input);
return $this->rule->evaluate($input)->withPrefixedId('undefOr');
}
if ($this->getName()) {

View file

@ -10,16 +10,10 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Helpers\CanBindEvaluateRule;
use Respect\Validation\Message\Template;
use Respect\Validation\Mode;
use Respect\Validation\Result;
use Respect\Validation\Rules\Core\Standard;
use Respect\Validation\Validatable;
#[Template(
'after asserting that',
'after failing to assert that',
)]
final class When extends Standard
{
use CanBindEvaluateRule;
@ -43,15 +37,9 @@ final class When extends Standard
{
$whenResult = $this->bindEvaluate($this->when, $this, $input);
if ($whenResult->isValid) {
$thenResult = $this->bindEvaluate($this->then, $this, $input);
$thisResult = new Result($thenResult->isValid, $input, $this);
return $thenResult->withNextSibling($thisResult->withNextSibling($whenResult));
return $this->bindEvaluate($this->then, $this, $input);
}
$elseResult = $this->bindEvaluate($this->else, $this, $input);
$thisResult = (new Result($elseResult->isValid, $input, $this))->withMode(Mode::NEGATIVE);
return $elseResult->withNextSibling($thisResult->withNextSibling($whenResult));
return $this->bindEvaluate($this->else, $this, $input);
}
}

View file

@ -0,0 +1,35 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Transformers;
use function array_keys;
use function in_array;
final class Aliases implements Transformer
{
private const ALIASES = [
'nullable' => 'nullOr',
'optional' => 'undefOr',
];
public function __construct(
private readonly Transformer $next
) {
}
public function transform(RuleSpec $ruleSpec): RuleSpec
{
if (!in_array($ruleSpec->name, array_keys(self::ALIASES), true)) {
return $this->next->transform($ruleSpec);
}
return new RuleSpec(self::ALIASES[$ruleSpec->name], $ruleSpec->arguments);
}
}

View file

@ -31,9 +31,11 @@ final class Prefix implements Transformer
'notEmoji',
'notEmpty',
'notOptional',
'nullOr',
'property',
'propertyExists',
'propertyOptional',
'undefOr',
];
public function transform(RuleSpec $ruleSpec): RuleSpec
@ -67,7 +69,7 @@ final class Prefix implements Transformer
}
if (str_starts_with($ruleSpec->name, 'nullOr')) {
return new RuleSpec(substr($ruleSpec->name, 6), $ruleSpec->arguments, new RuleSpec('nullable'));
return new RuleSpec(substr($ruleSpec->name, 6), $ruleSpec->arguments, new RuleSpec('nullOr'));
}
if (str_starts_with($ruleSpec->name, 'property')) {
@ -79,7 +81,7 @@ final class Prefix implements Transformer
}
if (str_starts_with($ruleSpec->name, 'undefOr')) {
return new RuleSpec(substr($ruleSpec->name, 7), $ruleSpec->arguments, new RuleSpec('optional'));
return new RuleSpec(substr($ruleSpec->name, 7), $ruleSpec->arguments, new RuleSpec('undefOr'));
}
return $ruleSpec;

View file

@ -75,7 +75,7 @@ final class Validator extends Standard
$templates = $this->templates;
if (count($templates) === 0 && $this->getTemplate() != null) {
$templates = ['__self__' => $this->getTemplate()];
$templates = ['__root__' => $this->getTemplate()];
}
throw new ValidationException(

View file

@ -15,4 +15,7 @@
<file>tests/</file>
<rule ref="Respect" />
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>tests/integration/</exclude-pattern>
</rule>
</ruleset>

View file

@ -39,13 +39,16 @@ exceptionMessages(static function (): void {
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
'mysql' => [
'__root__' => 'All of the required rules must pass for mysql',
'host' => 'host must be of type string',
'user' => 'user must be present',
'password' => 'password must be present',
'schema' => 'schema must be of type string',
],
'postgresql' => [
'__root__' => 'All of the required rules must pass for postgresql',
'host' => 'host must be present',
'user' => 'user must be of type string',
'password' => 'password must be of type string',

View file

@ -26,6 +26,7 @@ exceptionMessages(static function (): void {
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`',
'username' => 'The length of username must be between 2 and 32',
'birthdate' => 'birthdate must be a valid date/time',
'password' => 'password must not be empty',

View file

@ -50,13 +50,16 @@ exceptionMessages(
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
'mysql' => [
'__root__' => 'All of the required rules must pass for mysql',
'host' => '`host` should be a MySQL host',
'user' => 'Value should be a MySQL username',
'password' => 'password must be present',
'schema' => 'schema must be of type string',
],
'postgresql' => [
'__root__' => 'All of the required rules must pass for postgresql',
'host' => 'host must be present',
'user' => 'user must be of type string',
'password' => 'password must be of type string',

View file

@ -11,5 +11,5 @@ exceptionMessages(static fn () => v::key('firstname', v::notBlank()->setName('Fi
?>
--EXPECTF--
[
'First Name' => 'First Name must be present',
'firstname' => 'First Name must be present',
]

View file

@ -0,0 +1,17 @@
--FILE--
<?php
declare(strict_types=1);
use Respect\Validation\Validator as v;
require 'vendor/autoload.php';
exceptionMessages(static fn() => v::noWhitespace()->email()->setName('User Email')->assert('not email'));
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for User Email',
'noWhitespace' => 'User Email must not contain whitespace',
'email' => 'User Email must be valid email',
]

View file

@ -30,24 +30,31 @@ exceptionMessages(static function () use ($cars): void {
--EXPECT--
[
'each' => [
'__root__' => 'Each item in `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]` must be valid',
'oneOf.3' => [
'__root__' => 'Only one of these rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'allOf.1' => [
'__root__' => 'All of the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'manufacturer' => 'manufacturer must equal "Honda"',
'model' => 'model must be in `["Accord", "Fit"]`',
],
'allOf.2' => [
'__root__' => 'All of the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'manufacturer' => 'manufacturer must equal "Toyota"',
'model' => 'model must be in `["Rav4", "Camry"]`',
],
'allOf.3' => 'model must be in `["F150", "Bronco"]`',
],
'oneOf.4' => [
'__root__' => 'Only one of these rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'allOf.1' => 'model must be in `["Accord", "Fit"]`',
'allOf.2' => [
'__root__' => 'All of the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'manufacturer' => 'manufacturer must equal "Toyota"',
'model' => 'model must be in `["Rav4", "Camry"]`',
],
'allOf.3' => [
'__root__' => 'All of the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'manufacturer' => 'manufacturer must equal "Ford"',
'model' => 'model must be in `["F150", "Bronco"]`',
],

View file

@ -10,4 +10,4 @@ use Respect\Validation\Validator as v;
exceptionMessage(static fn() => v::when(v::alwaysInvalid(), v::alwaysValid())->check('foo'));
?>
--EXPECT--
"foo" is not valid after failing to assert that "foo" is always invalid
"foo" is not valid

View file

@ -21,7 +21,8 @@ exceptionMessages(
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for "really messed up screen#name"',
'alnum' => '"really messed up screen#name" must contain only letters and digits',
'noWhitespace' => '"really messed up screen#name" cannot contain spaces',
'length' => '"really messed up screen#name" must not have more than 15 chars',
]
'lengthBetween' => 'The length of "really messed up screen#name" must be between 1 and 15',
]

View file

@ -13,7 +13,8 @@ exceptionMessages(
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for "really messed up screen#name"',
'alnum' => '"really messed up screen#name" must contain only letters (a-z) and digits (0-9)',
'noWhitespace' => '"really messed up screen#name" must not contain whitespace',
'length' => 'The length of "really messed up screen#name" must be between 1 and 15',
'lengthBetween' => 'The length of "really messed up screen#name" must be between 1 and 15',
]

View file

@ -16,7 +16,7 @@ run([
v::allOf(v::stringType(), v::uppercase()),
5,
[
'__self__' => 'Two things are wrong',
'__root__' => 'Two things are wrong',
'stringType' => 'Template for "stringType"',
'uppercase' => 'Template for "uppercase"',
],
@ -31,6 +31,7 @@ Two rules
- "2" must be of type integer
- "2" must be negative
[
'__root__' => 'All of the required rules must pass for "2"',
'intType' => '"2" must be of type integer',
'negative' => '"2" must be negative',
]
@ -42,6 +43,7 @@ Wrapped by "not"
- 3 must not be of type integer
- 3 must not be positive
[
'__root__' => 'These rules must not pass for 3',
'intType' => '3 must not be of type integer',
'positive' => '3 must not be positive',
]
@ -51,7 +53,7 @@ Wrapping "not"
4 must not be of type integer
- 4 must not be of type integer
[
'intType' => '4 must not be of type integer',
'notIntType' => '4 must not be of type integer',
]
With a single template
@ -69,6 +71,7 @@ Template for "stringType"
- Template for "stringType"
- Template for "uppercase"
[
'__root__' => 'Two things are wrong',
'stringType' => 'Template for "stringType"',
'uppercase' => 'Template for "uppercase"',
]

View file

@ -28,7 +28,7 @@ Negative
5 must not be greater than 1 and less than 10
- 5 must not be greater than 1 and less than 10
[
'betweenExclusive' => '5 must not be greater than 1 and less than 10',
'notBetweenExclusive' => '5 must not be greater than 1 and less than 10',
]
With template
@ -44,6 +44,5 @@ With name
Range must be greater than 1 and less than 10
- Range must be greater than 1 and less than 10
[
'Range' => 'Range must be greater than 1 and less than 10',
'betweenExclusive' => 'Range must be greater than 1 and less than 10',
]

View file

@ -67,7 +67,7 @@ Negative
`true` must not evaluate to `true`
- `true` must not evaluate to `true`
[
'trueVal' => '`true` must not evaluate to `true`',
'notTrueVal' => '`true` must not evaluate to `true`',
]
Default with inverted failing rule
@ -75,7 +75,7 @@ Default with inverted failing rule
`true` must not evaluate to `true`
- `true` must not evaluate to `true`
[
'trueVal' => '`true` must not evaluate to `true`',
'notTrueVal' => '`true` must not evaluate to `true`',
]
With wrapped name, default
@ -83,7 +83,7 @@ With wrapped name, default
Wrapped must evaluate to `true`
- Wrapped must evaluate to `true`
[
'Wrapped' => 'Wrapped must evaluate to `true`',
'trueVal' => 'Wrapped must evaluate to `true`',
]
With wrapper name, default
@ -91,7 +91,7 @@ With wrapper name, default
Wrapper must evaluate to `true`
- Wrapper must evaluate to `true`
[
'Wrapper' => 'Wrapper must evaluate to `true`',
'trueVal' => 'Wrapper must evaluate to `true`',
]
With the name set in the wrapped rule of an inverted failing rule
@ -99,7 +99,7 @@ With the name set in the wrapped rule of an inverted failing rule
Wrapped must not evaluate to `true`
- Wrapped must not evaluate to `true`
[
'Wrapped' => 'Wrapped must not evaluate to `true`',
'notTrueVal' => 'Wrapped must not evaluate to `true`',
]
With the name set in an inverted failing rule
@ -107,7 +107,7 @@ With the name set in an inverted failing rule
Not must not evaluate to `true`
- Not must not evaluate to `true`
[
'Not' => 'Not must not evaluate to `true`',
'notTrueVal' => 'Not must not evaluate to `true`',
]
With the name set in the "consecutive" that has an inverted failing rule
@ -115,7 +115,7 @@ With the name set in the "consecutive" that has an inverted failing rule
Wrapper must not evaluate to `true`
- Wrapper must not evaluate to `true`
[
'Wrapper' => 'Wrapper must not evaluate to `true`',
'notTrueVal' => 'Wrapper must not evaluate to `true`',
]
With template

View file

@ -48,7 +48,7 @@ run([
v::each(v::intType()),
$default, [
'each' => [
'__self__' => 'Here a sequence of items that did not pass the validation',
'__root__' => 'Here a sequence of items that did not pass the validation',
'intType.1' => 'First item should have been an integer',
'intType.2' => 'Second item should have been an integer',
'intType.3' => 'Third item should have been an integer',
@ -59,7 +59,7 @@ run([
v::each(v::intType()->setName('Wrapped'))->setName('Wrapper'),
$default, [
'Wrapped' => [
'__self__' => 'Here a sequence of items that did not pass the validation',
'__root__' => 'Here a sequence of items that did not pass the validation',
'Wrapped.1' => 'First item should have been an integer',
'Wrapped.2' => 'Second item should have been an integer',
'Wrapped.3' => 'Third item should have been an integer',
@ -93,6 +93,7 @@ Default
- "b" must be of type integer
- "c" must be of type integer
[
'__root__' => 'Each item in `["a", "b", "c"]` must be valid',
'intType.1' => '"a" must be of type integer',
'intType.2' => '"b" must be of type integer',
'intType.3' => '"c" must be of type integer',
@ -106,6 +107,7 @@ Negative
- 2 must not be of type integer
- 3 must not be of type integer
[
'__root__' => 'Each item in `[1, 2, 3]` must not validate',
'intType.1' => '1 must not be of type integer',
'intType.2' => '2 must not be of type integer',
'intType.3' => '3 must not be of type integer',
@ -135,9 +137,10 @@ Wrapped must be of type integer
- Wrapped must be of type integer
- Wrapped must be of type integer
[
'Wrapped.1' => 'Wrapped must be of type integer',
'Wrapped.2' => 'Wrapped must be of type integer',
'Wrapped.3' => 'Wrapped must be of type integer',
'__root__' => 'Each item in Wrapped must be valid',
'intType.1' => 'Wrapped must be of type integer',
'intType.2' => 'Wrapped must be of type integer',
'intType.3' => 'Wrapped must be of type integer',
]
With name, negative
@ -148,9 +151,10 @@ Wrapped must not be of type integer
- Wrapped must not be of type integer
- Wrapped must not be of type integer
[
'Wrapped.1' => 'Wrapped must not be of type integer',
'Wrapped.2' => 'Wrapped must not be of type integer',
'Wrapped.3' => 'Wrapped must not be of type integer',
'__root__' => 'Each item in Wrapped must not validate',
'intType.1' => 'Wrapped must not be of type integer',
'intType.2' => 'Wrapped must not be of type integer',
'intType.3' => 'Wrapped must not be of type integer',
]
With wrapper name, default
@ -161,9 +165,10 @@ Wrapper must be of type integer
- Wrapper must be of type integer
- Wrapper must be of type integer
[
'Wrapper.1' => 'Wrapper must be of type integer',
'Wrapper.2' => 'Wrapper must be of type integer',
'Wrapper.3' => 'Wrapper must be of type integer',
'__root__' => 'Each item in Wrapper must be valid',
'intType.1' => 'Wrapper must be of type integer',
'intType.2' => 'Wrapper must be of type integer',
'intType.3' => 'Wrapper must be of type integer',
]
With wrapper name, negative
@ -174,9 +179,10 @@ Wrapper must not be of type integer
- Wrapper must not be of type integer
- Wrapper must not be of type integer
[
'Wrapper.1' => 'Wrapper must not be of type integer',
'Wrapper.2' => 'Wrapper must not be of type integer',
'Wrapper.3' => 'Wrapper must not be of type integer',
'__root__' => 'Each item in Wrapper must not validate',
'intType.1' => 'Wrapper must not be of type integer',
'intType.2' => 'Wrapper must not be of type integer',
'intType.3' => 'Wrapper must not be of type integer',
]
With Not name, negative
@ -187,9 +193,10 @@ Not must not be of type integer
- Not must not be of type integer
- Not must not be of type integer
[
'Not.1' => 'Not must not be of type integer',
'Not.2' => 'Not must not be of type integer',
'Not.3' => 'Not must not be of type integer',
'__root__' => 'Each item in Not must not validate',
'intType.1' => 'Not must not be of type integer',
'intType.2' => 'Not must not be of type integer',
'intType.3' => 'Not must not be of type integer',
]
With template, non-iterable
@ -221,7 +228,7 @@ with template, negative
All items should not have been integers
- All items should not have been integers
[
'each' => 'All items should not have been integers',
'notEach' => 'All items should not have been integers',
]
With array template, default
@ -232,6 +239,7 @@ First item should have been an integer
- Second item should have been an integer
- Third item should have been an integer
[
'__root__' => 'Here a sequence of items that did not pass the validation',
'intType.1' => 'First item should have been an integer',
'intType.2' => 'Second item should have been an integer',
'intType.3' => 'Third item should have been an integer',
@ -239,13 +247,14 @@ First item should have been an integer
With array template and name, default
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
First item should have been an integer
- Here a sequence of items that did not pass the validation
- First item should have been an integer
- Second item should have been an integer
- Third item should have been an integer
Wrapped must be of type integer
- Each item in Wrapped must be valid
- Wrapped must be of type integer
- Wrapped must be of type integer
- Wrapped must be of type integer
[
'Wrapped.1' => 'First item should have been an integer',
'Wrapped.2' => 'Second item should have been an integer',
'Wrapped.3' => 'Third item should have been an integer',
'__root__' => 'Each item in Wrapped must be valid',
'intType.1' => 'Wrapped must be of type integer',
'intType.2' => 'Wrapped must be of type integer',
'intType.3' => 'Wrapped must be of type integer',
]

View file

@ -28,7 +28,7 @@ Negative
"010106A9012" must not be a valid Finnish personal identity code
- "010106A9012" must not be a valid Finnish personal identity code
[
'hetu' => '"010106A9012" must not be a valid Finnish personal identity code',
'notHetu' => '"010106A9012" must not be a valid Finnish personal identity code',
]
With template
@ -44,6 +44,5 @@ With name
Hetu must be a valid Finnish personal identity code
- Hetu must be a valid Finnish personal identity code
[
'Hetu' => 'Hetu must be a valid Finnish personal identity code',
'hetu' => 'Hetu must be a valid Finnish personal identity code',
]

View file

@ -28,7 +28,7 @@ Negative
`[1, 2, 3]` must not of type iterable
- `[1, 2, 3]` must not of type iterable
[
'iterableType' => '`[1, 2, 3]` must not of type iterable',
'notIterableType' => '`[1, 2, 3]` must not of type iterable',
]
With template
@ -44,6 +44,5 @@ With name
Options must be of type iterable
- Options must be of type iterable
[
'Options' => 'Options must be of type iterable',
'iterableType' => 'Options must be of type iterable',
]

View file

@ -90,7 +90,7 @@ With wrapped name, missing key
Wrapped must be present
- Wrapped must be present
[
'Wrapped' => 'Wrapped must be present',
'foo' => 'Wrapped must be present',
]
With wrapped name, default
@ -98,7 +98,7 @@ With wrapped name, default
Wrapped must be of type integer
- Wrapped must be of type integer
[
'Wrapped' => 'Wrapped must be of type integer',
'foo' => 'Wrapped must be of type integer',
]
With wrapped name, negative
@ -106,7 +106,7 @@ With wrapped name, negative
Wrapped must not be of type integer
- Wrapped must not be of type integer
[
'Wrapped' => 'Wrapped must not be of type integer',
'foo' => 'Wrapped must not be of type integer',
]
With wrapper name, default
@ -156,4 +156,3 @@ No off-key key
[
'foo' => 'No off-key key',
]

View file

@ -36,7 +36,7 @@ Custom name
Custom name must be present
- Custom name must be present
[
'Custom name' => 'Custom name must be present',
'foo' => 'Custom name must be present',
]
Custom template
@ -46,4 +46,3 @@ Custom template for `foo`
[
'foo' => 'Custom template for `foo`',
]

View file

@ -73,7 +73,7 @@ With wrapped name, default
Wrapped must be of type integer
- Wrapped must be of type integer
[
'Wrapped' => 'Wrapped must be of type integer',
'foo' => 'Wrapped must be of type integer',
]
With wrapped name, negative
@ -81,7 +81,7 @@ With wrapped name, negative
Wrapped must not be of type integer
- Wrapped must not be of type integer
[
'Wrapped' => 'Wrapped must not be of type integer',
'foo' => 'Wrapped must not be of type integer',
]
With wrapper name, default
@ -123,4 +123,3 @@ No off-key key
[
'foo' => 'No off-key key',
]

View file

@ -51,7 +51,7 @@ Negative
2 must not be of type integer
- 2 must not be of type integer
[
'intType' => '2 must not be of type integer',
'notIntType' => '2 must not be of type integer',
]
With created name, default
@ -59,7 +59,7 @@ With created name, default
Created must be of type integer
- Created must be of type integer
[
'Created' => 'Created must be of type integer',
'intType' => 'Created must be of type integer',
]
With wrapper name, default
@ -67,7 +67,7 @@ With wrapper name, default
Wrapper must be of type integer
- Wrapper must be of type integer
[
'Wrapper' => 'Wrapper must be of type integer',
'intType' => 'Wrapper must be of type integer',
]
With created name, negative
@ -75,7 +75,7 @@ With created name, negative
Created must not be of type integer
- Created must not be of type integer
[
'Created' => 'Created must not be of type integer',
'notIntType' => 'Created must not be of type integer',
]
With wrapper name, negative
@ -83,7 +83,7 @@ With wrapper name, negative
Wrapped must not be of type integer
- Wrapped must not be of type integer
[
'Wrapped' => 'Wrapped must not be of type integer',
'notIntType' => 'Wrapped must not be of type integer',
]
With not name, negative
@ -91,7 +91,7 @@ With not name, negative
Not must not be of type integer
- Not must not be of type integer
[
'Not' => 'Not must not be of type integer',
'notIntType' => 'Not must not be of type integer',
]
With template, default
@ -101,4 +101,3 @@ Lazy lizards lounging like lords in the local lagoon
[
'intType' => 'Lazy lizards lounging like lords in the local lagoon',
]

View file

@ -21,7 +21,7 @@ Default
The length of "tulip" must equal 3
- The length of "tulip" must equal 3
[
'length' => 'The length of "tulip" must equal 3',
'lengthEquals' => 'The length of "tulip" must equal 3',
]
Negative wrapped
@ -29,7 +29,7 @@ Negative wrapped
The length of "rose" must not equal 4
- The length of "rose" must not equal 4
[
'length' => 'The length of "rose" must not equal 4',
'lengthNotEquals' => 'The length of "rose" must not equal 4',
]
Negative wrapper
@ -37,7 +37,7 @@ Negative wrapper
The length of "fern" must not equal 4
- The length of "fern" must not equal 4
[
'length' => 'The length of "fern" must not equal 4',
'notLengthEquals' => 'The length of "fern" must not equal 4',
]
With template
@ -45,7 +45,7 @@ With template
This is a template
- This is a template
[
'length' => 'This is a template',
'lengthEquals' => 'This is a template',
]
With wrapper name
@ -53,5 +53,5 @@ With wrapper name
The length of Cactus must equal 3
- The length of Cactus must equal 3
[
'Cactus' => 'The length of Cactus must equal 3',
'lengthEquals' => 'The length of Cactus must equal 3',
]

View file

@ -48,7 +48,7 @@ Default
As the maximum of `[1, 2, 3]`, 3 must be negative
- As the maximum of `[1, 2, 3]`, 3 must be negative
[
'max' => 'As the maximum of `[1, 2, 3]`, 3 must be negative',
'maxNegative' => 'As the maximum of `[1, 2, 3]`, 3 must be negative',
]
Negative
@ -56,7 +56,7 @@ Negative
As the maximum of `[-3, -2, -1]`, -1 must not be negative
- As the maximum of `[-3, -2, -1]`, -1 must not be negative
[
'max' => 'As the maximum of `[-3, -2, -1]`, -1 must not be negative',
'notMaxNegative' => 'As the maximum of `[-3, -2, -1]`, -1 must not be negative',
]
With wrapped name, default
@ -64,7 +64,7 @@ With wrapped name, default
The maximum of Wrapped must be negative
- The maximum of Wrapped must be negative
[
'Wrapped' => 'The maximum of Wrapped must be negative',
'maxNegative' => 'The maximum of Wrapped must be negative',
]
With wrapper name, default
@ -72,7 +72,7 @@ With wrapper name, default
The maximum of Wrapper must be negative
- The maximum of Wrapper must be negative
[
'Wrapper' => 'The maximum of Wrapper must be negative',
'maxNegative' => 'The maximum of Wrapper must be negative',
]
With wrapped name, negative
@ -80,7 +80,7 @@ With wrapped name, negative
The maximum of Wrapped must not be negative
- The maximum of Wrapped must not be negative
[
'Wrapped' => 'The maximum of Wrapped must not be negative',
'notMaxNegative' => 'The maximum of Wrapped must not be negative',
]
With wrapper name, negative
@ -88,7 +88,7 @@ With wrapper name, negative
The maximum of Wrapper must not be negative
- The maximum of Wrapper must not be negative
[
'Wrapper' => 'The maximum of Wrapper must not be negative',
'notMaxNegative' => 'The maximum of Wrapper must not be negative',
]
With template, default
@ -96,5 +96,5 @@ With template, default
The maximum of the value is not what we expect
- The maximum of the value is not what we expect
[
'max' => 'The maximum of the value is not what we expect',
'maxNegative' => 'The maximum of the value is not what we expect',
]

View file

@ -20,7 +20,7 @@ Default
As the minimum from `[2, 3]`, 2 must equal 1
- As the minimum from `[2, 3]`, 2 must equal 1
[
'min' => 'As the minimum from `[2, 3]`, 2 must equal 1',
'minEquals' => 'As the minimum from `[2, 3]`, 2 must equal 1',
]
Negative
@ -28,7 +28,7 @@ Negative
As the minimum from `[1, 2, 3]`, 1 must not equal 1
- As the minimum from `[1, 2, 3]`, 1 must not equal 1
[
'min' => 'As the minimum from `[1, 2, 3]`, 1 must not equal 1',
'notMinEquals' => 'As the minimum from `[1, 2, 3]`, 1 must not equal 1',
]
With template
@ -36,7 +36,7 @@ With template
That did not go as planned
- That did not go as planned
[
'min' => 'That did not go as planned',
'minEquals' => 'That did not go as planned',
]
With name
@ -44,6 +44,5 @@ With name
The minimum from Options must equal 1
- The minimum from Options must equal 1
[
'Options' => 'The minimum from Options must equal 1',
'minEquals' => 'The minimum from Options must equal 1',
]

View file

@ -0,0 +1,93 @@
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
run([
'Default' => [v::nullOr(v::alpha()), 1234],
'Negative wrapper' => [v::not(v::nullOr(v::alpha())), 'alpha'],
'Negative wrapped' => [v::nullOr(v::not(v::alpha())), 'alpha'],
'Negative nullined' => [v::not(v::nullOr(v::alpha())), null],
'Negative nullined, wrapped name' => [v::not(v::nullOr(v::alpha()->setName('Wrapped'))), null],
'Negative nullined, wrapper name' => [v::not(v::nullOr(v::alpha())->setName('Wrapper')), null],
'Negative nullined, not name' => [v::not(v::nullOr(v::alpha()))->setName('Not'), null],
'With template' => [v::nullOr(v::alpha()), 123, 'Nine nimble numismatists near Naples'],
'With array template' => [v::nullOr(v::alpha()), 123, ['nullOrAlpha' => 'Next to nifty null notations']],
]);
?>
--EXPECT--
Default
⎺⎺⎺⎺⎺⎺⎺
1234 must contain only letters (a-z)
- 1234 must contain only letters (a-z)
[
'nullOrAlpha' => '1234 must contain only letters (a-z)',
]
Negative wrapper
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
"alpha" must not contain letters (a-z)
- "alpha" must not contain letters (a-z)
[
'notNullOrAlpha' => '"alpha" must not contain letters (a-z)',
]
Negative wrapped
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
"alpha" must not contain letters (a-z)
- "alpha" must not contain letters (a-z)
[
'nullOrNotAlpha' => '"alpha" must not contain letters (a-z)',
]
Negative nullined
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
The value must not be null
- The value must not be null
[
'notNullOr' => 'The value must not be null',
]
Negative nullined, wrapped name
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Wrapped must not be null
- Wrapped must not be null
[
'notNullOr' => 'Wrapped must not be null',
]
Negative nullined, wrapper name
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Wrapper must not be null
- Wrapper must not be null
[
'notNullOr' => 'Wrapper must not be null',
]
Negative nullined, not name
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Not must not be null
- Not must not be null
[
'notNullOr' => 'Not must not be null',
]
With template
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Nine nimble numismatists near Naples
- Nine nimble numismatists near Naples
[
'nullOrAlpha' => 'Nine nimble numismatists near Naples',
]
With array template
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Next to nifty null notations
- Next to nifty null notations
[
'nullOrAlpha' => 'Next to nifty null notations',
]

View file

@ -1,27 +0,0 @@
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
exceptionMessage(static fn() => v::optional(v::alpha())->check(1234));
exceptionMessage(static fn() => v::optional(v::alpha())->setName('Name')->check(1234));
exceptionMessage(static fn() => v::not(v::optional(v::alpha()))->check('abcd'));
exceptionMessage(static fn() => v::not(v::optional(v::alpha()))->setName('Name')->check('abcd'));
exceptionFullMessage(static fn() => v::optional(v::alpha())->assert(1234));
exceptionFullMessage(static fn() => v::optional(v::alpha())->setName('Name')->assert(1234));
exceptionFullMessage(static fn() => v::not(v::optional(v::alpha()))->assert('abcd'));
exceptionFullMessage(static fn() => v::not(v::optional(v::alpha()))->setName('Name')->assert('abcd'));
?>
--EXPECT--
1234 must contain only letters (a-z)
Name must contain only letters (a-z)
"abcd" must not contain letters (a-z)
Name must not contain letters (a-z)
- 1234 must contain only letters (a-z)
- Name must contain only letters (a-z)
- "abcd" must not contain letters (a-z)
- Name must not contain letters (a-z)

View file

@ -37,7 +37,7 @@ Negative
"+55 11 91111 1111" must not be a valid telephone number
- "+55 11 91111 1111" must not be a valid telephone number
[
'phone' => '"+55 11 91111 1111" must not be a valid telephone number',
'notPhone' => '"+55 11 91111 1111" must not be a valid telephone number',
]
Default with name
@ -45,7 +45,7 @@ Default with name
Phone must be a valid telephone number
- Phone must be a valid telephone number
[
'Phone' => 'Phone must be a valid telephone number',
'phone' => 'Phone must be a valid telephone number',
]
Country-specific with name
@ -53,5 +53,5 @@ Country-specific with name
Phone must be a valid telephone number for country United States
- Phone must be a valid telephone number for country United States
[
'Phone' => 'Phone must be a valid telephone number for country United States',
'phone' => 'Phone must be a valid telephone number for country United States',
]

View file

@ -98,7 +98,7 @@ With wrapped name, missing property
Wrapped must be present
- Wrapped must be present
[
'Wrapped' => 'Wrapped must be present',
'foo' => 'Wrapped must be present',
]
With wrapped name, default
@ -106,7 +106,7 @@ With wrapped name, default
Wrapped must be of type integer
- Wrapped must be of type integer
[
'Wrapped' => 'Wrapped must be of type integer',
'foo' => 'Wrapped must be of type integer',
]
With wrapped name, negative
@ -114,7 +114,7 @@ With wrapped name, negative
Wrapped must not be of type integer
- Wrapped must not be of type integer
[
'Wrapped' => 'Wrapped must not be of type integer',
'foo' => 'Wrapped must not be of type integer',
]
With wrapper name, default
@ -164,4 +164,3 @@ Not a prompt prospect of a particularly primitive property
[
'foo' => 'Not a prompt prospect of a particularly primitive property',
]

View file

@ -36,7 +36,7 @@ Custom name
Custom name must be present
- Custom name must be present
[
'Custom name' => 'Custom name must be present',
'foo' => 'Custom name must be present',
]
Custom template
@ -46,4 +46,3 @@ Custom template for `foo`
[
'foo' => 'Custom template for `foo`',
]

View file

@ -81,7 +81,7 @@ With wrapped name, default
Wrapped must be of type integer
- Wrapped must be of type integer
[
'Wrapped' => 'Wrapped must be of type integer',
'foo' => 'Wrapped must be of type integer',
]
With wrapped name, negative
@ -89,7 +89,7 @@ With wrapped name, negative
Wrapped must not be of type integer
- Wrapped must not be of type integer
[
'Wrapped' => 'Wrapped must not be of type integer',
'foo' => 'Wrapped must not be of type integer',
]
With wrapper name, default
@ -131,4 +131,3 @@ Not proving prudent property planning promotes prosperity
[
'foo' => 'Not proving prudent property planning promotes prosperity',
]

View file

@ -0,0 +1,85 @@
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
run([
'Default' => [v::undefOr(v::alpha()), 1234],
'Negative wrapper' => [v::not(v::undefOr(v::alpha())), 'alpha'],
'Negative wrapped' => [v::undefOr(v::not(v::alpha())), 'alpha'],
'Negative undefined' => [v::not(v::undefOr(v::alpha())), null],
'Negative undefined, wrapped name' => [v::not(v::undefOr(v::alpha()->setName('Wrapped'))), null],
'Negative undefined, wrapped name' => [v::not(v::undefOr(v::alpha())->setName('Wrapper')), null],
'Negative undefined, not name' => [v::not(v::undefOr(v::alpha()))->setName('Not'), null],
'With template' => [v::undefOr(v::alpha()), 123, 'Underneath the undulating umbrella'],
'With array template' => [v::undefOr(v::alpha()), 123, ['undefOrAlpha' => 'Undefined number of unique unicorns']],
]);
?>
--EXPECT--
Default
⎺⎺⎺⎺⎺⎺⎺
1234 must contain only letters (a-z)
- 1234 must contain only letters (a-z)
[
'undefOrAlpha' => '1234 must contain only letters (a-z)',
]
Negative wrapper
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
"alpha" must not contain letters (a-z)
- "alpha" must not contain letters (a-z)
[
'notUndefOrAlpha' => '"alpha" must not contain letters (a-z)',
]
Negative wrapped
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
"alpha" must not contain letters (a-z)
- "alpha" must not contain letters (a-z)
[
'undefOrNotAlpha' => '"alpha" must not contain letters (a-z)',
]
Negative undefined
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
The value must not be undefined
- The value must not be undefined
[
'notUndefOr' => 'The value must not be undefined',
]
Negative undefined, wrapped name
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Wrapper must not be undefined
- Wrapper must not be undefined
[
'notUndefOr' => 'Wrapper must not be undefined',
]
Negative undefined, not name
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Not must not be undefined
- Not must not be undefined
[
'notUndefOr' => 'Not must not be undefined',
]
With template
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Underneath the undulating umbrella
- Underneath the undulating umbrella
[
'undefOrAlpha' => 'Underneath the undulating umbrella',
]
With array template
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
Undefined number of unique unicorns
- Undefined number of unique unicorns
[
'undefOrAlpha' => 'Undefined number of unique unicorns',
]

View file

@ -41,18 +41,18 @@ run([
--EXPECT--
When valid use "then"
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
-1 must be positive after asserting that -1 must be an integer number
- -1 must be positive after asserting that -1 must be an integer number
-1 must be positive
- -1 must be positive
[
'positive' => '-1 must be positive after asserting that -1 must be an integer number',
'positive' => '-1 must be positive',
]
When invalid use "else"
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
The value must not be empty after failing to assert that "" must be an integer number
- The value must not be empty after failing to assert that "" must be an integer number
The value must not be empty
- The value must not be empty
[
'notEmpty' => 'The value must not be empty after failing to assert that "" must be an integer number',
'notEmpty' => 'The value must not be empty',
]
When valid use "then" using single template

View file

@ -0,0 +1,21 @@
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
run([
'optional' => [v::optional(v::scalarVal()), []],
]);
?>
--EXPECT--
optional
⎺⎺⎺⎺⎺⎺⎺⎺
`[]` must be a scalar value
- `[]` must be a scalar value
[
'undefOrScalarVal' => '`[]` must be a scalar value',
]

View file

@ -21,12 +21,11 @@ exceptionMessage(static fn() => v::keyNested('foo.bar')->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar', v::stringType())->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar.baz', v::notEmpty(), false)->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar', v::floatType(), false)->assert($input));
// phpcs:disable Generic.Files.LineLength.TooLong
?>
--EXPECTF--
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
foo must be present after asserting that `["foo.bar.baz": false]` must be an array value
foo must be present
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
No exception was thrown

View file

@ -33,7 +33,7 @@ length
The length of "foo" must be greater than 3
- The length of "foo" must be greater than 3
[
'length' => 'The length of "foo" must be greater than 3',
'lengthGreaterThan' => 'The length of "foo" must be greater than 3',
]
max
@ -41,7 +41,7 @@ max
As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number
- As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number
[
'max' => 'As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number',
'maxOdd' => 'As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number',
]
min
@ -49,7 +49,7 @@ min
As the minimum from `[1, 2, 3]`, 1 must be an even number
- As the minimum from `[1, 2, 3]`, 1 must be an even number
[
'min' => 'As the minimum from `[1, 2, 3]`, 1 must be an even number',
'minEven' => 'As the minimum from `[1, 2, 3]`, 1 must be an even number',
]
not
@ -57,7 +57,7 @@ not
2 must not be between 1 and 3
- 2 must not be between 1 and 3
[
'between' => '2 must not be between 1 and 3',
'notBetween' => '2 must not be between 1 and 3',
]
nullOr
@ -65,7 +65,7 @@ nullOr
"string" must be of type boolean
- "string" must be of type boolean
[
'boolType' => '"string" must be of type boolean',
'nullOrBoolType' => '"string" must be of type boolean',
]
property
@ -81,5 +81,5 @@ undefOr
"string" must be a URL
- "string" must be a URL
[
'url' => '"string" must be a URL',
'undefOrUrl' => '"string" must be a URL',
]

View file

@ -0,0 +1,21 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Test\Transformers;
use Respect\Validation\Transformers\RuleSpec;
use Respect\Validation\Transformers\Transformer;
final class StubTransformer implements Transformer
{
public function transform(RuleSpec $ruleSpec): RuleSpec
{
return $ruleSpec;
}
}

View file

@ -0,0 +1,41 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\TestCase;
#[CoversClass(InvalidRuleConstructorException::class)]
final class InvalidRuleConstructorExceptionTest extends TestCase
{
/** @param array<string|array<string>> $arguments */
#[Test]
#[DataProvider('providerForMessages')]
public function itShouldCreateMessageForWithString(string $expect, string $format, array $arguments): void
{
$exception = new InvalidRuleConstructorException($format, ...$arguments);
self::assertEquals($expect, $exception->getMessage());
}
/** @return array<string, array{0: string, 1: string, 2: array<string|array<string>>}> */
public static function providerForMessages(): array
{
return [
'with 1 argument' => ['-arg-', '-%s-', ['arg']],
'with 2 arguments' => ['-arg1- _arg2_', '-%s- _%s_', ['arg1', 'arg2']],
'with an array of 1 elements' => ['_"arg1"_', '_%s_', [['arg1']]],
'with an array of 2 elements' => ['_"arg1" and "arg2"_', '_%s_', [['arg1', 'arg2']]],
'with an array of 3+ elements' => ['_"arg1", "arg2", and "arg3"_', '_%s_', [['arg1', 'arg2', 'arg3']]],
];
}
}

View file

@ -0,0 +1,28 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\TestCase;
#[CoversClass(MissingComposerDependencyException::class)]
final class MissingComposerDependencyExceptionTest extends TestCase
{
#[Test]
public function itShouldCreateMessageForMultipleDependencies(): void
{
$exception = new MissingComposerDependencyException('message', 'dependency1', 'dependency2');
$expected = 'message. Run `composer require dependency1 dependency2` to fix this issue.';
self::assertEquals($expected, $exception->getMessage());
}
}

View file

@ -32,6 +32,7 @@ trait ArrayProvider
'with single-level children, without templates' => [
self::singleLevelChildrenMessage(),
[
'__root__' => '__parent_original__',
'1st' => '__1st_original__',
'2nd' => '__2nd_original__',
'3rd' => '__3rd_original__',
@ -40,12 +41,13 @@ trait ArrayProvider
'with single-level children, with templates' => [
self::singleLevelChildrenMessage(),
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
],
[
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
@ -54,7 +56,7 @@ trait ArrayProvider
'with single-level children, with partial templates' => [
self::singleLevelChildrenMessage(),
[
'__root__' => '__parent_original__',
'1st' => '1st custom',
'2nd' => '__2nd_original__',
'3rd' => '3rd custom',
@ -72,7 +74,7 @@ trait ArrayProvider
'with single-nested child, without templates' => [
self::multiLevelChildrenWithSingleNestedChildMessage(),
[
'__root__' => '__parent_original__',
'1st' => '__1st_original__',
'2nd' => '__2nd_1st_original__',
'3rd' => '__3rd_original__',
@ -81,12 +83,13 @@ trait ArrayProvider
'with single-nested child, with templates' => [
self::multiLevelChildrenWithSingleNestedChildMessage(),
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd > 1st custom',
'3rd' => '3rd custom',
],
[
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_1st' => '2nd > 1st custom',
@ -97,12 +100,13 @@ trait ArrayProvider
'with single-nested child, with partial templates' => [
self::multiLevelChildrenWithSingleNestedChildMessage(),
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '__2nd_1st_original__',
'3rd' => '3rd custom',
],
[
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_2nd' => '2nd > 2nd not shown',
@ -113,11 +117,13 @@ trait ArrayProvider
'with single-nested child, with overwritten templates' => [
self::multiLevelChildrenWithSingleNestedChildMessage(),
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
],
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
@ -126,8 +132,10 @@ trait ArrayProvider
'with multi-nested children, without templates' => [
self::multiLevelChildrenWithMultiNestedChildrenMessage(),
[
'__root__' => '__parent_original__',
'1st' => '__1st_original__',
'2nd' => [
'__root__' => '__2nd_original__',
'2nd_1st' => '__2nd_1st_original__',
'2nd_2nd' => '__2nd_2nd_original__',
],
@ -137,16 +145,20 @@ trait ArrayProvider
'with multi-nested children, with templates' => [
self::multiLevelChildrenWithMultiNestedChildrenMessage(),
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'__root__' => '2nd custom',
'2nd_1st' => '2nd > 1st custom',
'2nd_2nd' => '2nd > 2nd custom',
],
'3rd' => '3rd custom',
],
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'__root__' => '2nd custom',
'2nd_1st' => '2nd > 1st custom',
'2nd_2nd' => '2nd > 2nd custom',
],
@ -156,27 +168,28 @@ trait ArrayProvider
'with multi-nested children, with partial templates' => [
self::multiLevelChildrenWithMultiNestedChildrenMessage(),
[
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'__root__' => '__2nd_original__',
'2nd_1st' => '__2nd_1st_original__',
'2nd_2nd' => '2nd > 2nd custom',
],
'3rd' => '3rd custom',
],
[
'parent' => [
'__self__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_2nd' => '2nd > 2nd custom',
],
'3rd' => '3rd custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_2nd' => '2nd > 2nd custom',
],
'3rd' => '3rd custom',
],
],
'with children with the same id, without templates' => [
self::singleLevelChildrenWithSameId(),
[
'__root__' => '__parent_original__',
'child.1' => '__1st_original__',
'child.2' => '__2nd_original__',
'child.3' => '__3rd_original__',
@ -185,11 +198,13 @@ trait ArrayProvider
'with children with the same id, with templates' => [
self::singleLevelChildrenWithSameId(),
[
'__root__' => 'Parent custom',
'child.1' => '1st custom',
'child.2' => '2nd custom',
'child.3' => '3rd custom',
],
[
'__root__' => 'Parent custom',
'child.1' => '1st custom',
'child.2' => '2nd custom',
'child.3' => '3rd custom',
@ -198,6 +213,7 @@ trait ArrayProvider
'with children with the same id, with partial templates' => [
self::singleLevelChildrenWithSameId(),
[
'__root__' => '__parent_original__',
'child.1' => '1st custom',
'child.2' => '2nd custom',
'child.3' => '__3rd_original__',

View file

@ -48,7 +48,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
@ -96,7 +96,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_1st' => '2nd > 1st custom',
@ -115,7 +115,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_2nd' => '2nd > 2nd not shown',
@ -134,7 +134,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
@ -164,10 +164,10 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'__self__' => '2nd custom',
'__root__' => '2nd custom',
'2nd_1st' => '2nd > 1st custom',
'2nd_2nd' => '2nd > 2nd custom',
],
@ -187,7 +187,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => [
'2nd_2nd' => '2nd > 2nd custom',
@ -206,7 +206,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
'3rd' => '3rd custom',
@ -232,7 +232,7 @@ trait FullProvider
MESSAGE,
[
'parent' => [
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'child.1' => '1st custom',
'child.2' => '2nd custom',
'child.3' => '3rd custom',

View file

@ -49,7 +49,7 @@ trait MainProvider
->build(),
'Parent custom',
[
'__self__' => 'Parent custom',
'__root__' => 'Parent custom',
'1st' => '1st custom',
'2nd' => '2nd custom',
],

View file

@ -13,7 +13,7 @@ use DateTime;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
use Respect\Validation\Test\Stubs\CountableStub;
@ -24,7 +24,8 @@ final class BetweenTest extends RuleTestCase
#[Test]
public function minimumValueShouldNotBeGreaterThanMaximumValue(): void
{
$this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum'));
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('Minimum cannot be less than or equals to maximum');
new Between(10, 5);
}
@ -32,7 +33,8 @@ final class BetweenTest extends RuleTestCase
#[Test]
public function minimumValueShouldNotBeEqualsToMaximumValue(): void
{
$this->expectExceptionObject(new ComponentException('Minimum cannot be less than or equals to maximum'));
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('Minimum cannot be less than or equals to maximum');
new Between(5, 5);
}

View file

@ -12,7 +12,7 @@ namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
#[Group('rule')]
@ -22,11 +22,8 @@ final class CreditCardTest extends RuleTestCase
#[Test]
public function itShouldThrowExceptionWhenCreditCardBrandIsNotValid(): void
{
$message = '"RespectCard" is not a valid credit card brand';
$message .= ' (Available: Any, American Express, Diners Club, Discover, JCB, MasterCard, Visa, RuPay)';
$this->expectException(ComponentException::class);
$this->expectExceptionMessage($message);
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessageMatches('/"RespectCard" is not a valid credit card brand \(Available: .+\)/');
new CreditCard('RespectCard');
}

View file

@ -15,7 +15,7 @@ use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
#[Group('rule')]
@ -26,7 +26,7 @@ final class DateTest extends RuleTestCase
#[DataProvider('validFormatsProvider')]
public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
new Date($format);
}

View file

@ -12,7 +12,7 @@ namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
use const FILTER_FLAG_HOSTNAME;
@ -32,7 +32,7 @@ final class FilterVarTest extends RuleTestCase
#[Test]
public function itShouldThrowsExceptionWhenFilterIsNotValid(): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('Cannot accept the given filter');
new FilterVar(FILTER_SANITIZE_EMAIL);

View file

@ -13,7 +13,7 @@ use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
use function extension_loaded;
@ -29,7 +29,7 @@ final class IpTest extends RuleTestCase
#[DataProvider('providerForInvalidRanges')]
public function invalidRangeShouldRaiseException(string $range): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
new Ip($range);
}

View file

@ -28,7 +28,7 @@ final class NotTest extends RuleTestCase
self::assertEquals(
$rule->evaluate('input'),
$wrapped->evaluate('input')->withInvertedMode()
$wrapped->evaluate('input')->withPrefixedId('not')->withInvertedMode()
);
}

View file

@ -0,0 +1,84 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\Rules\Stub;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
#[Group('rule')]
#[CoversClass(NullOr::class)]
final class NullOrTest extends RuleTestCase
{
#[Test]
public function itShouldUseStandardTemplateWhenItHasNameWhenInputIsOptional(): void
{
$rule = new NullOr(Stub::pass(1));
$result = $rule->evaluate(null);
self::assertSame($rule, $result->rule);
self::assertSame(NullOr::TEMPLATE_STANDARD, $result->template);
}
#[Test]
public function itShouldUseNamedTemplateWhenItHasNameWhenInputIsNullable(): void
{
$rule = new NullOr(Stub::pass(1));
$rule->setName('foo');
$result = $rule->evaluate(null);
self::assertSame($rule, $result->rule);
self::assertSame(NullOr::TEMPLATE_NAMED, $result->template);
}
#[Test]
public function itShouldUseWrappedRuleToEvaluateWhenNotNullable(): void
{
$input = new stdClass();
$wrapped = Stub::pass(2);
$rule = new NullOr($wrapped);
self::assertEquals($wrapped->evaluate($input)->withPrefixedId('nullOr'), $rule->evaluate($input));
}
/** @return iterable<string, array{NullOr, mixed}> */
public static function providerForValidInput(): iterable
{
yield 'null' => [new NullOr(Stub::daze()), null];
yield 'not null with passing rule' => [new NullOr(Stub::pass(1)), 42];
}
/** @return iterable<array{NullOr, mixed}> */
public static function providerForInvalidInput(): iterable
{
yield [new NullOr(Stub::fail(1)), ''];
yield [new NullOr(Stub::fail(1)), 1];
yield [new NullOr(Stub::fail(1)), []];
yield [new NullOr(Stub::fail(1)), ' '];
yield [new NullOr(Stub::fail(1)), 0];
yield [new NullOr(Stub::fail(1)), '0'];
yield [new NullOr(Stub::fail(1)), 0];
yield [new NullOr(Stub::fail(1)), '0.0'];
yield [new NullOr(Stub::fail(1)), false];
yield [new NullOr(Stub::fail(1)), ['']];
yield [new NullOr(Stub::fail(1)), [' ']];
yield [new NullOr(Stub::fail(1)), [0]];
yield [new NullOr(Stub::fail(1)), ['0']];
yield [new NullOr(Stub::fail(1)), [false]];
yield [new NullOr(Stub::fail(1)), [[''], [0]]];
yield [new NullOr(Stub::fail(1)), new stdClass()];
}
}

View file

@ -1,84 +0,0 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\Rules\Stub;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
#[Group('rule')]
#[CoversClass(Nullable::class)]
final class NullableTest extends RuleTestCase
{
#[Test]
public function itShouldUseStandardTemplateWhenItHasNameWhenInputIsOptional(): void
{
$rule = new Nullable(Stub::pass(1));
$result = $rule->evaluate(null);
self::assertSame($rule, $result->rule);
self::assertSame(Nullable::TEMPLATE_STANDARD, $result->template);
}
#[Test]
public function itShouldUseNamedTemplateWhenItHasNameWhenInputIsNullable(): void
{
$rule = new Nullable(Stub::pass(1));
$rule->setName('foo');
$result = $rule->evaluate(null);
self::assertSame($rule, $result->rule);
self::assertSame(Nullable::TEMPLATE_NAMED, $result->template);
}
#[Test]
public function itShouldUseWrappedRuleToEvaluateWhenNotNullable(): void
{
$input = new stdClass();
$wrapped = Stub::pass(2);
$rule = new Nullable($wrapped);
self::assertEquals($wrapped->evaluate($input), $rule->evaluate($input));
}
/** @return iterable<string, array{Nullable, mixed}> */
public static function providerForValidInput(): iterable
{
yield 'null' => [new Nullable(Stub::daze()), null];
yield 'not null with passing rule' => [new Nullable(Stub::pass(1)), 42];
}
/** @return iterable<array{Nullable, mixed}> */
public static function providerForInvalidInput(): iterable
{
yield [new Nullable(Stub::fail(1)), ''];
yield [new Nullable(Stub::fail(1)), 1];
yield [new Nullable(Stub::fail(1)), []];
yield [new Nullable(Stub::fail(1)), ' '];
yield [new Nullable(Stub::fail(1)), 0];
yield [new Nullable(Stub::fail(1)), '0'];
yield [new Nullable(Stub::fail(1)), 0];
yield [new Nullable(Stub::fail(1)), '0.0'];
yield [new Nullable(Stub::fail(1)), false];
yield [new Nullable(Stub::fail(1)), ['']];
yield [new Nullable(Stub::fail(1)), [' ']];
yield [new Nullable(Stub::fail(1)), [0]];
yield [new Nullable(Stub::fail(1)), ['0']];
yield [new Nullable(Stub::fail(1)), [false]];
yield [new Nullable(Stub::fail(1)), [[''], [0]]];
yield [new Nullable(Stub::fail(1)), new stdClass()];
}
}

View file

@ -1,84 +0,0 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\Rules\Stub;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
#[Group('rule')]
#[CoversClass(Optional::class)]
final class OptionalTest extends RuleTestCase
{
#[Test]
public function itShouldUseStandardTemplateWhenItHasNameWhenInputIsOptional(): void
{
$rule = new Optional(Stub::pass(1));
$result = $rule->evaluate('');
self::assertSame($rule, $result->rule);
self::assertSame(Optional::TEMPLATE_STANDARD, $result->template);
}
#[Test]
public function itShouldUseNamedTemplateWhenItHasNameWhenInputIsOptional(): void
{
$rule = new Optional(Stub::pass(1));
$rule->setName('foo');
$result = $rule->evaluate('');
self::assertSame($rule, $result->rule);
self::assertSame(Optional::TEMPLATE_NAMED, $result->template);
}
#[Test]
public function itShouldUseWrappedRuleToEvaluateWhenNotOptional(): void
{
$input = new stdClass();
$wrapped = Stub::pass(2);
$rule = new Optional($wrapped);
self::assertEquals($wrapped->evaluate($input), $rule->evaluate($input));
}
/** @return iterable<string, array{Optional, mixed}> */
public static function providerForValidInput(): iterable
{
yield 'null' => [new Optional(Stub::daze()), null];
yield 'empty string' => [new Optional(Stub::daze()), ''];
yield 'not optional' => [new Optional(Stub::pass(1)), 42];
}
/** @return iterable<array{Optional, mixed}> */
public static function providerForInvalidInput(): iterable
{
yield [new Optional(Stub::fail(1)), 1];
yield [new Optional(Stub::fail(1)), []];
yield [new Optional(Stub::fail(1)), ' '];
yield [new Optional(Stub::fail(1)), 0];
yield [new Optional(Stub::fail(1)), '0'];
yield [new Optional(Stub::fail(1)), 0];
yield [new Optional(Stub::fail(1)), '0.0'];
yield [new Optional(Stub::fail(1)), false];
yield [new Optional(Stub::fail(1)), ['']];
yield [new Optional(Stub::fail(1)), [' ']];
yield [new Optional(Stub::fail(1)), [0]];
yield [new Optional(Stub::fail(1)), ['0']];
yield [new Optional(Stub::fail(1)), [false]];
yield [new Optional(Stub::fail(1)), [[''], [0]]];
yield [new Optional(Stub::fail(1)), new stdClass()];
}
}

View file

@ -12,7 +12,7 @@ namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
#[Group('rule')]
@ -38,7 +38,7 @@ final class PostalCodeTest extends RuleTestCase
#[Test]
public function shouldThrowsExceptionWhenCountryCodeIsNotValid(): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('Cannot validate postal code from "Whatever" country');
new PostalCode('Whatever');

View file

@ -14,7 +14,7 @@ use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
use Respect\Validation\Test\Stubs\StreamStub;
use Respect\Validation\Test\Stubs\UploadedFileStub;
@ -27,7 +27,7 @@ final class SizeTest extends RuleTestCase
#[Test]
public function shouldThrowsAnExceptionWhenSizeIsNotValid(): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('"42jb" is not a recognized file size');
new Size('42jb');

View file

@ -12,7 +12,7 @@ namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
@ -23,7 +23,8 @@ final class SortedTest extends RuleTestCase
#[Test]
public function itShouldNotAcceptWrongSortingDirection(): void
{
$this->expectExceptionObject(new ComponentException('Direction should be either "ASC" or "DESC"'));
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('Direction should be either "ASC" or "DESC"');
new Sorted('something');
}

View file

@ -12,7 +12,7 @@ namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
#[Group('rule')]
@ -22,7 +22,7 @@ final class SubdivisionCodeTest extends RuleTestCase
#[Test]
public function shouldNotAcceptWrongNamesOnConstructor(): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
$this->expectExceptionMessage('"whatever" is not a supported country code');
new SubdivisionCode('whatever');

View file

@ -15,7 +15,7 @@ use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
use Respect\Validation\Test\RuleTestCase;
#[Group('rule')]
@ -26,7 +26,7 @@ final class TimeTest extends RuleTestCase
#[DataProvider('invalidFormatsProvider')]
public function shouldThrowAnExceptionWhenFormatIsNotValid(string $format): void
{
$this->expectException(ComponentException::class);
$this->expectException(InvalidRuleConstructorException::class);
new Time($format);
}

View file

@ -0,0 +1,84 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\Rules\Stub;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
#[Group('rule')]
#[CoversClass(UndefOr::class)]
final class UndefOrTest extends RuleTestCase
{
#[Test]
public function itShouldUseStandardTemplateWhenItHasNameWhenInputIsOptional(): void
{
$rule = new UndefOr(Stub::pass(1));
$result = $rule->evaluate('');
self::assertSame($rule, $result->rule);
self::assertSame(UndefOr::TEMPLATE_STANDARD, $result->template);
}
#[Test]
public function itShouldUseNamedTemplateWhenItHasNameWhenInputIsOptional(): void
{
$rule = new UndefOr(Stub::pass(1));
$rule->setName('foo');
$result = $rule->evaluate('');
self::assertSame($rule, $result->rule);
self::assertSame(UndefOr::TEMPLATE_NAMED, $result->template);
}
#[Test]
public function itShouldUseWrappedRuleToEvaluateWhenNotOptional(): void
{
$input = new stdClass();
$wrapped = Stub::pass(2);
$rule = new UndefOr($wrapped);
self::assertEquals($wrapped->evaluate($input)->withPrefixedId('undefOr'), $rule->evaluate($input));
}
/** @return iterable<string, array{UndefOr, mixed}> */
public static function providerForValidInput(): iterable
{
yield 'null' => [new UndefOr(Stub::daze()), null];
yield 'empty string' => [new UndefOr(Stub::daze()), ''];
yield 'not optional' => [new UndefOr(Stub::pass(1)), 42];
}
/** @return iterable<array{UndefOr, mixed}> */
public static function providerForInvalidInput(): iterable
{
yield [new UndefOr(Stub::fail(1)), 1];
yield [new UndefOr(Stub::fail(1)), []];
yield [new UndefOr(Stub::fail(1)), ' '];
yield [new UndefOr(Stub::fail(1)), 0];
yield [new UndefOr(Stub::fail(1)), '0'];
yield [new UndefOr(Stub::fail(1)), 0];
yield [new UndefOr(Stub::fail(1)), '0.0'];
yield [new UndefOr(Stub::fail(1)), false];
yield [new UndefOr(Stub::fail(1)), ['']];
yield [new UndefOr(Stub::fail(1)), [' ']];
yield [new UndefOr(Stub::fail(1)), [0]];
yield [new UndefOr(Stub::fail(1)), ['0']];
yield [new UndefOr(Stub::fail(1)), [false]];
yield [new UndefOr(Stub::fail(1)), [[''], [0]]];
yield [new UndefOr(Stub::fail(1)), new stdClass()];
}
}

Some files were not shown because too many files have changed in this diff Show more