Skip to content

Commit 1d6e75e

Browse files
committed
Rename When to LogicCond
The name `When` was ambiguous and didn't clearly convey its purpose as a conditional validator. The new name `LogicCond` clearly indicates this is a logical conditional operation (if-then-else) where validation follows different paths based on whether a condition passes or fails. This rename is part of a broader effort to improve the naming of composite rules in version 3.0, making them more intuitive and reducing potential confusion when implementing validation logic.
1 parent 5ec8765 commit 1d6e75e

28 files changed

Lines changed: 125 additions & 118 deletions

docs/feature-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Respect\Validation offers over 150 validators, many of which are designed to add
4040
- Validating **Arrays**: [Key](validators/Key.md), [KeyOptional](validators/KeyOptional.md), [KeyExists](validators/KeyExists.md).
4141
- Validating **Array structures**: [KeySet](validators/KeySet.md).
4242
- Validating **Object properties**: [Property](validators/Property.md), [PropertyOptional](validators/PropertyOptional.md), [PropertyExists](validators/PropertyExists.md).
43-
- Using **Conditional validation**: [NullOr](validators/NullOr.md), [UndefOr](validators/UndefOr.md), [When](validators/When.md).
43+
- Using **Conditional validation**: [NullOr](validators/NullOr.md), [UndefOr](validators/UndefOr.md), [LogicCond](validators/LogicCond.md).
4444
- Using **Logical validation**: [LogicAnd](validators/LogicAnd.md), [LogicOr](validators/LogicOr.md), [LogicNor](validators/LogicNor.md), [LogicXor](validators/LogicXor.md)
4545
- Validating **Each** value in the input: [Each](validators/Each.md).
4646
- Validating the **Length** of the input: [Length](validators/Length.md).

docs/list-of-validators-by-category.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
## Conditions
6868

6969
- [Circuit](validators/Circuit.md)
70+
- [LogicCond](validators/LogicCond.md)
7071
- [Not](validators/Not.md)
71-
- [When](validators/When.md)
7272

7373
## Core
7474

@@ -147,6 +147,7 @@
147147
## Logical
148148

149149
- [LogicAnd](validators/LogicAnd.md)
150+
- [LogicCond](validators/LogicCond.md)
150151
- [LogicNor](validators/LogicNor.md)
151152
- [LogicOr](validators/LogicOr.md)
152153
- [LogicXor](validators/LogicXor.md)
@@ -181,6 +182,7 @@
181182
- [KeySet](validators/KeySet.md)
182183
- [Lazy](validators/Lazy.md)
183184
- [LogicAnd](validators/LogicAnd.md)
185+
- [LogicCond](validators/LogicCond.md)
184186
- [LogicNor](validators/LogicNor.md)
185187
- [LogicOr](validators/LogicOr.md)
186188
- [LogicXor](validators/LogicXor.md)
@@ -189,7 +191,6 @@
189191
- [Property](validators/Property.md)
190192
- [PropertyOptional](validators/PropertyOptional.md)
191193
- [UndefOr](validators/UndefOr.md)
192-
- [When](validators/When.md)
193194

194195
## Numbers
195196

@@ -398,6 +399,7 @@
398399
- [LessThan](validators/LessThan.md)
399400
- [LessThanOrEqual](validators/LessThanOrEqual.md)
400401
- [LogicAnd](validators/LogicAnd.md)
402+
- [LogicCond](validators/LogicCond.md)
401403
- [LogicNor](validators/LogicNor.md)
402404
- [LogicOr](validators/LogicOr.md)
403405
- [LogicXor](validators/LogicXor.md)
@@ -467,6 +469,5 @@
467469
- [Version](validators/Version.md)
468470
- [VideoUrl](validators/VideoUrl.md)
469471
- [Vowel](validators/Vowel.md)
470-
- [When](validators/When.md)
471472
- [Writable](validators/Writable.md)
472473
- [Xdigit](validators/Xdigit.md)

docs/validators/AlwaysInvalid.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ v::alwaysInvalid()->isValid('whatever'); // false
4545
See also:
4646

4747
- [AlwaysValid](AlwaysValid.md)
48-
- [When](When.md)
48+
- [LogicCond](LogicCond.md)

docs/validators/Circuit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ v::circuit(
1717
```
1818

1919
You need a valid country code to create a [SubdivisionCode](SubdivisionCode.md), so it makes sense only to validate the
20-
subdivision code only if the country code is valid. In this case, you could also have used [When](When.md), but you
20+
subdivision code only if the country code is valid. In this case, you could also have used [LogicCond](LogicCond.md), but you
2121
would then have to write `v::key('countryCode', v::countryCode())` twice in your chain.
2222

2323
## Templates
@@ -42,8 +42,8 @@ See also:
4242

4343
- [Lazy](Lazy.md)
4444
- [LogicAnd](LogicAnd.md)
45+
- [LogicCond](LogicCond.md)
4546
- [LogicNor](LogicNor.md)
4647
- [LogicOr](LogicOr.md)
4748
- [LogicXor](LogicXor.md)
4849
- [SubdivisionCode](SubdivisionCode.md)
49-
- [When](When.md)

docs/validators/LogicAnd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Used when all validators have failed.
5252
See also:
5353

5454
- [Circuit](Circuit.md)
55+
- [LogicCond](LogicCond.md)
5556
- [LogicNor](LogicNor.md)
5657
- [LogicOr](LogicOr.md)
5758
- [LogicXor](LogicXor.md)
58-
- [When](When.md)
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
# When
1+
# LogicCond
22

3-
- `When(Validator $if, Validator $then)`
4-
- `When(Validator $if, Validator $then, Validator $else)`
3+
- `LogicCond(Validator $if, Validator $then)`
4+
- `LogicCond(Validator $if, Validator $then, Validator $else)`
55

6-
A ternary validator that accepts three parameters.
6+
A conditional validator that applies logic based on the validation results.
77

8-
When the `$if` validates, returns validation for `$then`.
9-
When the `$if` doesn't validate, returns validation for `$else`, if defined.
8+
If the `$if` validator passes, it applies the `$then` validator. If the `$if` validator fails, it applies the `$else` validator (if provided); otherwise, validation fails.
109

1110
```php
12-
v::when(v::intVal(), v::positive(), v::notBlank())->isValid(1); // true
13-
v::when(v::intVal(), v::positive(), v::notBlank())->isValid('non-blank string'); // true
11+
v::logicCond(v::intVal(), v::positive(), v::notBlank())->isValid(1); // true
12+
v::logicCond(v::intVal(), v::positive(), v::notBlank())->isValid('non-blank string'); // true
1413

15-
v::when(v::intVal(), v::positive(), v::notBlank())->isValid(-1); // false
16-
v::when(v::intVal(), v::positive(), v::notBlank())->isValid(''); // false
14+
v::logicCond(v::intVal(), v::positive(), v::notBlank())->isValid(-1); // false
15+
v::logicCond(v::intVal(), v::positive(), v::notBlank())->isValid(''); // false
1716
```
1817

1918
In the sample above, if `$input` is an integer, then it must be positive.
@@ -31,14 +30,16 @@ When `$else` is not defined use [AlwaysInvalid](AlwaysInvalid.md)
3130
## Categorization
3231

3332
- Conditions
33+
- Logical
3434
- Nesting
3535

3636
## Changelog
3737

3838
| Version | Description |
3939
| ------: | ----------------------------------- |
40+
| 3.0.0 | Renamed to `LogicCond` |
4041
| 0.8.0 | Allow to use validator without else |
41-
| 0.3.9 | Created |
42+
| 0.3.9 | Created as `When` |
4243

4344
---
4445

docs/validators/LogicNor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ See also:
5858

5959
- [Circuit](Circuit.md)
6060
- [LogicAnd](LogicAnd.md)
61+
- [LogicCond](LogicCond.md)
6162
- [LogicOr](LogicOr.md)
6263
- [LogicXor](LogicXor.md)
6364
- [Not](Not.md)
64-
- [When](When.md)

docs/validators/LogicOr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ See also:
4848
- [Circuit](Circuit.md)
4949
- [ContainsAny](ContainsAny.md)
5050
- [LogicAnd](LogicAnd.md)
51+
- [LogicCond](LogicCond.md)
5152
- [LogicNor](LogicNor.md)
5253
- [LogicXor](LogicXor.md)
53-
- [When](When.md)

docs/validators/LogicXor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ See also:
5959

6060
- [Circuit](Circuit.md)
6161
- [LogicAnd](LogicAnd.md)
62+
- [LogicCond](LogicCond.md)
6263
- [LogicNor](LogicNor.md)
6364
- [LogicOr](LogicOr.md)
64-
- [When](When.md)

library/Mixins/AllBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ public static function allLogicAnd(
197197
Validator ...$validators,
198198
): Chain;
199199

200+
public static function allLogicCond(Validator $logicCond, Validator $then, Validator|null $else = null): Chain;
201+
200202
public static function allLogicNor(
201203
Validator $validator1,
202204
Validator $validator2,
@@ -329,8 +331,6 @@ public static function allVideoUrl(string|null $service = null): Chain;
329331

330332
public static function allVowel(string ...$additionalChars): Chain;
331333

332-
public static function allWhen(Validator $when, Validator $then, Validator|null $else = null): Chain;
333-
334334
public static function allWritable(): Chain;
335335

336336
public static function allXdigit(string ...$additionalChars): Chain;

0 commit comments

Comments
 (0)