Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/create-mixin
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use Respect\Validation\Mixins\NotBuilder;
use Respect\Validation\Mixins\NullOrBuilder;
use Respect\Validation\Mixins\PropertyBuilder;
use Respect\Validation\Mixins\UndefOrBuilder;
use Respect\Validation\Rules\NotUndef;
use Respect\Validation\Rules\Undef;
use Respect\Validation\Rules\NullOr;
use Respect\Validation\Rules\UndefOr;
use Respect\Validation\Rule;
Expand Down Expand Up @@ -172,10 +172,10 @@ function overwriteFile(string $content, string $basename): void
['Length', 'length', $numberRelatedRules, []],
['Max', 'max', $numberRelatedRules, []],
['Min', 'min', $numberRelatedRules, []],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotEmoji', 'NotUndef', 'NullOr', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['NullOr', 'nullOr', [], ['NullOr', 'Blank', 'NotUndef', 'UndefOr', 'Templated', 'Named']],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotEmoji', 'NullOr', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['NullOr', 'nullOr', [], ['NullOr', 'Blank', 'Undef', 'UndefOr', 'Templated', 'Named']],
['Property', 'property', [], $structureRelatedRules],
['UndefOr', 'undefOr', [], ['NullOr', 'Blank', 'NotUndef', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['UndefOr', 'undefOr', [], ['NullOr', 'Blank', 'Undef', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['', null, [], []],
];

Expand Down
4 changes: 2 additions & 2 deletions docs/09-list-of-rules-by-category.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
- [FilterVar](rules/FilterVar.md)
- [Named](rules/Named.md)
- [NotEmpty](rules/NotEmpty.md)
- [NotUndef](rules/NotUndef.md)
- [Templated](rules/Templated.md)
- [Undef](rules/Undef.md)

## Nesting

Expand Down Expand Up @@ -406,7 +406,6 @@
- [Not](rules/Not.md)
- [NotEmoji](rules/NotEmoji.md)
- [NotEmpty](rules/NotEmpty.md)
- [NotUndef](rules/NotUndef.md)
- [NoWhitespace](rules/NoWhitespace.md)
- [NullOr](rules/NullOr.md)
- [NullType](rules/NullType.md)
Expand Down Expand Up @@ -451,6 +450,7 @@
- [Tld](rules/Tld.md)
- [TrueVal](rules/TrueVal.md)
- [Type](rules/Type.md)
- [Undef](rules/Undef.md)
- [UndefOr](rules/UndefOr.md)
- [Unique](rules/Unique.md)
- [Uploaded](rules/Uploaded.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Example of object:
use Respect\Validation\Rules as Rule;

#[Rule\AnyOf(
new Rule\Property('email', new Rule\NotUndef()),
new Rule\Property('phone', new Rule\NotUndef()),
new Rule\Property('email', new Rule\Not(new Rule\Undef())),
new Rule\Property('phone', new Rule\Not(new Rule\Undef())),
)]
final class Person
{
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Blank.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ It's similar to [NotEmpty](NotEmpty.md), but way stricter.
See also:

- [NotEmpty](NotEmpty.md)
- [NotUndef](NotUndef.md)
- [NoWhitespace](NoWhitespace.md)
- [NullType](NullType.md)
- [Number](Number.md)
- [Undef](Undef.md)
- [UndefOr](UndefOr.md)
2 changes: 1 addition & 1 deletion docs/rules/NoWhitespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ See also:
- [Blank](Blank.md)
- [CreditCard](CreditCard.md)
- [NotEmpty](NotEmpty.md)
- [NotUndef](NotUndef.md)
- [Undef](Undef.md)
- [UndefOr](UndefOr.md)
2 changes: 1 addition & 1 deletion docs/rules/NotEmpty.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ See also:
- [Each](Each.md)
- [Max](Max.md)
- [Min](Min.md)
- [NotUndef](NotUndef.md)
- [NoWhitespace](NoWhitespace.md)
- [NullType](NullType.md)
- [Number](Number.md)
- [Undef](Undef.md)
- [UndefOr](UndefOr.md)
67 changes: 0 additions & 67 deletions docs/rules/NotUndef.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/rules/NullType.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ See also:
- [FloatType](FloatType.md)
- [IntType](IntType.md)
- [NotEmpty](NotEmpty.md)
- [NotUndef](NotUndef.md)
- [NullOr](NullOr.md)
- [Number](Number.md)
- [ObjectType](ObjectType.md)
- [ResourceType](ResourceType.md)
- [StringType](StringType.md)
- [StringVal](StringVal.md)
- [Type](Type.md)
- [Undef](Undef.md)
- [UndefOr](UndefOr.md)
2 changes: 1 addition & 1 deletion docs/rules/Number.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ See also:
- [FloatType](FloatType.md)
- [IntType](IntType.md)
- [NotEmpty](NotEmpty.md)
- [NotUndef](NotUndef.md)
- [NullType](NullType.md)
- [NumericVal](NumericVal.md)
- [ObjectType](ObjectType.md)
- [ResourceType](ResourceType.md)
- [StringType](StringType.md)
- [Type](Type.md)
- [Undef](Undef.md)
65 changes: 65 additions & 0 deletions docs/rules/Undef.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Undef

- `Undef()`

Validates if the given input is undefined. By _undefined_ we consider `null` or an empty string (`''`).

```php
v::undef()->isValid(''); // true
v::undef()->isValid(null); // true
```

Other values similar to _undefined_ values are considered _defined_:

```php
v::undef()->isValid([]); // false
v::undef()->isValid(' '); // false
v::undef()->isValid(0); // false
v::undef()->isValid('0'); // false
v::undef()->isValid('0.0'); // false
v::undef()->isValid(false); // false
v::undef()->isValid(['']); // false
v::undef()->isValid([' ']); // false
v::undef()->isValid([0]); // false
v::undef()->isValid(['0']); // false
v::undef()->isValid([false]); // false
v::undef()->isValid([[''], [0]]); // false
v::undef()->isValid(new stdClass()); // false
```

## Templates

### `Undef::TEMPLATE_STANDARD`

| Mode | Template |
| ---------- | ----------------------------- |
| `default` | {{subject}} must be undefined |
| `inverted` | {{subject}} must be defined |

## Template placeholders

| Placeholder | Description |
| ----------- | ---------------------------------------------------------------- |
| `subject` | The validated input or the custom validator name (if specified). |

## Categorization

- Miscellaneous

## Changelog

| Version | Description |
| ------: | ------------------------------------------- |
| 3.0.0 | Renamed to `Undef` and changed the behavior |
| 1.0.0 | Created as `NotOptional` |

---

See also:

- [Blank](Blank.md)
- [NotEmpty](NotEmpty.md)
- [NoWhitespace](NoWhitespace.md)
- [NullType](NullType.md)
- [Number](Number.md)
- [UndefOr](UndefOr.md)
2 changes: 1 addition & 1 deletion docs/rules/UndefOr.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ See also:

- [Blank](Blank.md)
- [NotEmpty](NotEmpty.md)
- [NotUndef](NotUndef.md)
- [NoWhitespace](NoWhitespace.md)
- [NullOr](NullOr.md)
- [NullType](NullType.md)
- [Undef](Undef.md)
4 changes: 2 additions & 2 deletions library/Mixins/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ public static function notEmoji(): Chain;

public static function notEmpty(): Chain;

public static function notUndef(): Chain;

public static function nullOr(Rule $rule): Chain;

public static function nullType(): Chain;
Expand Down Expand Up @@ -337,6 +335,8 @@ public static function tld(): Chain;

public static function trueVal(): Chain;

public static function undef(): Chain;

public static function undefOr(Rule $rule): Chain;

public static function unique(): Chain;
Expand Down
4 changes: 2 additions & 2 deletions library/Mixins/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ public function notEmoji(): Chain;

public function notEmpty(): Chain;

public function notUndef(): Chain;

public function nullOr(Rule $rule): Chain;

public function nullType(): Chain;
Expand Down Expand Up @@ -340,6 +338,8 @@ public function tld(): Chain;

public function trueVal(): Chain;

public function undef(): Chain;

public function undefOr(Rule $rule): Chain;

public function unique(): Chain;
Expand Down
4 changes: 2 additions & 2 deletions library/Mixins/KeyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public static function keyNotEmoji(int|string $key): Chain;

public static function keyNotEmpty(int|string $key): Chain;

public static function keyNotUndef(int|string $key): Chain;

public static function keyNullType(int|string $key): Chain;

public static function keyNumber(int|string $key): Chain;
Expand Down Expand Up @@ -305,6 +303,8 @@ public static function keyTld(int|string $key): Chain;

public static function keyTrueVal(int|string $key): Chain;

public static function keyUndef(int|string $key): Chain;

public static function keyUnique(int|string $key): Chain;

public static function keyUploaded(int|string $key): Chain;
Expand Down
4 changes: 2 additions & 2 deletions library/Mixins/KeyChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public function keyNotEmoji(int|string $key): Chain;

public function keyNotEmpty(int|string $key): Chain;

public function keyNotUndef(int|string $key): Chain;

public function keyNullType(int|string $key): Chain;

public function keyNumber(int|string $key): Chain;
Expand Down Expand Up @@ -305,6 +303,8 @@ public function keyTld(int|string $key): Chain;

public function keyTrueVal(int|string $key): Chain;

public function keyUndef(int|string $key): Chain;

public function keyUnique(int|string $key): Chain;

public function keyUploaded(int|string $key): Chain;
Expand Down
2 changes: 2 additions & 0 deletions library/Mixins/NotBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public static function notTld(): Chain;

public static function notTrueVal(): Chain;

public static function notUndef(): Chain;

public static function notUnique(): Chain;

public static function notUploaded(): Chain;
Expand Down
2 changes: 2 additions & 0 deletions library/Mixins/NotChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public function notTld(): Chain;

public function notTrueVal(): Chain;

public function notUndef(): Chain;

public function notUnique(): Chain;

public function notUploaded(): Chain;
Expand Down
4 changes: 2 additions & 2 deletions library/Mixins/PropertyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ public static function propertyNotEmoji(string $propertyName): Chain;

public static function propertyNotEmpty(string $propertyName): Chain;

public static function propertyNotUndef(string $propertyName): Chain;

public static function propertyNullType(string $propertyName): Chain;

public static function propertyNumber(string $propertyName): Chain;
Expand Down Expand Up @@ -313,6 +311,8 @@ public static function propertyTld(string $propertyName): Chain;

public static function propertyTrueVal(string $propertyName): Chain;

public static function propertyUndef(string $propertyName): Chain;

public static function propertyUnique(string $propertyName): Chain;

public static function propertyUploaded(string $propertyName): Chain;
Expand Down
4 changes: 2 additions & 2 deletions library/Mixins/PropertyChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public function propertyNotEmoji(string $propertyName): Chain;

public function propertyNotEmpty(string $propertyName): Chain;

public function propertyNotUndef(string $propertyName): Chain;

public function propertyNullType(string $propertyName): Chain;

public function propertyNumber(string $propertyName): Chain;
Expand Down Expand Up @@ -305,6 +303,8 @@ public function propertyTld(string $propertyName): Chain;

public function propertyTrueVal(string $propertyName): Chain;

public function propertyUndef(string $propertyName): Chain;

public function propertyUnique(string $propertyName): Chain;

public function propertyUploaded(string $propertyName): Chain;
Expand Down
Loading