Skip to content

Commit fb32edc

Browse files
committed
Rename "Consecutive" to "Circuit"
The "Consecutive" rule is now renamed to "Circuit" to better reflect its behavior of stopping at the first failure. I also favour this name because it's much shorter.
1 parent e465810 commit fb32edc

26 files changed

+68
-65
lines changed

docs/02-feature-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Respect\Validation offers over 150 rules, many of which are designed to address
4343
* Validating the **Length** of the input: [Length](rules/Length.md).
4444
* Validating the **Maximum** value in the input: [Max](rules/Max.md).
4545
* Validating the **Minimum** value in the input: [Min](rules/Min.md).
46-
* Handling **Special cases**: [Lazy](rules/Lazy.md), [Consecutive](rules/Consecutive.md), [Call](rules/Call.md).
46+
* Handling **Special cases**: [Lazy](rules/Lazy.md), [Circuit](rules/Circuit.md), [Call](rules/Call.md).
4747

4848
### Custom templates
4949

docs/rules/AllOf.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ v::allOf(v::intVal(), v::positive())->isValid(15); // true
4646
See also:
4747

4848
- [AnyOf](AnyOf.md)
49+
- [Circuit](Circuit.md)
4950
- [Consecutive](Consecutive.md)
5051
- [NoneOf](NoneOf.md)
5152
- [OneOf](OneOf.md)

docs/rules/AnyOf.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ so `AnyOf()` returns true.
4444
See also:
4545

4646
- [AllOf](AllOf.md)
47+
- [Circuit](Circuit.md)
4748
- [Consecutive](Consecutive.md)
4849
- [ContainsAny](ContainsAny.md)
4950
- [NoneOf](NoneOf.md)

docs/rules/Consecutive.md docs/rules/Circuit.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Consecutive
1+
# Circuit
22

3-
- `Consecutive(Rule $rule1, Rule $rule2, Rule ...$rule)`
3+
- `Circuit(Rule $rule1, Rule $rule2, Rule ...$rule)`
44

5-
Validates the input against a series of rules until one fails.
5+
Validates the input against a series of rules until the first fails.
66

77
This rule can be handy for getting the least error messages possible from a chain.
88

99
This rule can be helpful in combinations with [Lazy](Lazy.md). An excellent example is when you want to validate a
1010
country code and a subdivision code.
1111

1212
```php
13-
v::consecutive(
13+
v::circuit(
1414
v::key('countryCode', v::countryCode()),
1515
v::lazy(static fn($input) => v::key('subdivisionCode', v::subdivisionCode($input['countryCode']))),
1616
)->isValid($_POST);
@@ -22,11 +22,7 @@ would then have to write `v::key('countryCode', v::countryCode())` twice in your
2222

2323
## Templates
2424

25-
## Template placeholders
26-
27-
| Placeholder | Description |
28-
|-------------|------------------------------------------------------------------|
29-
| `name` | The validated input or the custom validator name (if specified). |
25+
This rule does not have any templates, because it will always return the result of the first rule that fails. When all the validation rules pass, it will return the result of the last rule of the circuit.
3026

3127
## Categorization
3228

docs/rules/Lazy.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ See also:
4747

4848
- [Call](Call.md)
4949
- [CallableType](CallableType.md)
50+
- [Circuit](Circuit.md)
5051
- [Consecutive](Consecutive.md)

docs/rules/NoneOf.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ See also:
4545

4646
- [AllOf](AllOf.md)
4747
- [AnyOf](AnyOf.md)
48+
- [Circuit](Circuit.md)
4849
- [Consecutive](Consecutive.md)
4950
- [Not](Not.md)
5051
- [OneOf](OneOf.md)

docs/rules/OneOf.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ See also:
4646

4747
- [AllOf](AllOf.md)
4848
- [AnyOf](AnyOf.md)
49+
- [Circuit](Circuit.md)
4950
- [Consecutive](Consecutive.md)
5051
- [NoneOf](NoneOf.md)
5152
- [When](When.md)

docs/rules/SubdivisionCode.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ v::subdivisionCode('US')->isValid('CA'); // true
4444
***
4545
See also:
4646

47+
- [Circuit](Circuit.md)
4748
- [Consecutive](Consecutive.md)
4849
- [CountryCode](CountryCode.md)
4950
- [CurrencyCode](CurrencyCode.md)

docs/rules/When.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ See also:
4646
- [AllOf](AllOf.md)
4747
- [AlwaysInvalid](AlwaysInvalid.md)
4848
- [AnyOf](AnyOf.md)
49+
- [Circuit](Circuit.md)
4950
- [Consecutive](Consecutive.md)
5051
- [NoneOf](NoneOf.md)
5152
- [OneOf](OneOf.md)

library/Mixins/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public static function callback(callable $callback, mixed ...$arguments): Chain;
6565

6666
public static function charset(string $charset, string ...$charsets): Chain;
6767

68+
public static function circuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
69+
6870
public static function cnh(): Chain;
6971

7072
public static function cnpj(): Chain;
7173

72-
public static function consecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
73-
7474
public static function consonant(string ...$additionalChars): Chain;
7575

7676
public static function contains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/Chain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public function callback(callable $callback, mixed ...$arguments): Chain;
7070

7171
public function charset(string $charset, string ...$charsets): Chain;
7272

73+
public function circuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
74+
7375
public function cnh(): Chain;
7476

7577
public function cnpj(): Chain;
7678

77-
public function consecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
78-
7979
public function consonant(string ...$additionalChars): Chain;
8080

8181
public function contains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/KeyBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public static function keyCallback(int|string $key, callable $callback, mixed ..
5656

5757
public static function keyCharset(int|string $key, string $charset, string ...$charsets): Chain;
5858

59+
public static function keyCircuit(int|string $key, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
60+
5961
public static function keyCnh(int|string $key): Chain;
6062

6163
public static function keyCnpj(int|string $key): Chain;
6264

63-
public static function keyConsecutive(int|string $key, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
64-
6565
public static function keyConsonant(int|string $key, string ...$additionalChars): Chain;
6666

6767
public static function keyContains(int|string $key, mixed $containsValue, bool $identical = false): Chain;

library/Mixins/KeyChain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public function keyCallback(int|string $key, callable $callback, mixed ...$argum
5656

5757
public function keyCharset(int|string $key, string $charset, string ...$charsets): Chain;
5858

59+
public function keyCircuit(int|string $key, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
60+
5961
public function keyCnh(int|string $key): Chain;
6062

6163
public function keyCnpj(int|string $key): Chain;
6264

63-
public function keyConsecutive(int|string $key, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
64-
6565
public function keyConsonant(int|string $key, string ...$additionalChars): Chain;
6666

6767
public function keyContains(int|string $key, mixed $containsValue, bool $identical = false): Chain;

library/Mixins/NotBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public static function notCallback(callable $callback, mixed ...$arguments): Cha
5555

5656
public static function notCharset(string $charset, string ...$charsets): Chain;
5757

58+
public static function notCircuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
59+
5860
public static function notCnh(): Chain;
5961

6062
public static function notCnpj(): Chain;
6163

62-
public static function notConsecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
63-
6464
public static function notConsonant(string ...$additionalChars): Chain;
6565

6666
public static function notContains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/NotChain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public function notCallback(callable $callback, mixed ...$arguments): Chain;
5555

5656
public function notCharset(string $charset, string ...$charsets): Chain;
5757

58+
public function notCircuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
59+
5860
public function notCnh(): Chain;
5961

6062
public function notCnpj(): Chain;
6163

62-
public function notConsecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
63-
6464
public function notConsonant(string ...$additionalChars): Chain;
6565

6666
public function notContains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/NullOrBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public static function nullOrCallback(callable $callback, mixed ...$arguments):
5757

5858
public static function nullOrCharset(string $charset, string ...$charsets): Chain;
5959

60+
public static function nullOrCircuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
61+
6062
public static function nullOrCnh(): Chain;
6163

6264
public static function nullOrCnpj(): Chain;
6365

64-
public static function nullOrConsecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
65-
6666
public static function nullOrConsonant(string ...$additionalChars): Chain;
6767

6868
public static function nullOrContains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/NullOrChain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public function nullOrCallback(callable $callback, mixed ...$arguments): Chain;
5757

5858
public function nullOrCharset(string $charset, string ...$charsets): Chain;
5959

60+
public function nullOrCircuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
61+
6062
public function nullOrCnh(): Chain;
6163

6264
public function nullOrCnpj(): Chain;
6365

64-
public function nullOrConsecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
65-
6666
public function nullOrConsonant(string ...$additionalChars): Chain;
6767

6868
public function nullOrContains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/PropertyBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public static function propertyCallback(string $propertyName, callable $callback
5656

5757
public static function propertyCharset(string $propertyName, string $charset, string ...$charsets): Chain;
5858

59+
public static function propertyCircuit(string $propertyName, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
60+
5961
public static function propertyCnh(string $propertyName): Chain;
6062

6163
public static function propertyCnpj(string $propertyName): Chain;
6264

63-
public static function propertyConsecutive(string $propertyName, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
64-
6565
public static function propertyConsonant(string $propertyName, string ...$additionalChars): Chain;
6666

6767
public static function propertyContains(

library/Mixins/PropertyChain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public function propertyCallback(string $propertyName, callable $callback, mixed
5656

5757
public function propertyCharset(string $propertyName, string $charset, string ...$charsets): Chain;
5858

59+
public function propertyCircuit(string $propertyName, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
60+
5961
public function propertyCnh(string $propertyName): Chain;
6062

6163
public function propertyCnpj(string $propertyName): Chain;
6264

63-
public function propertyConsecutive(string $propertyName, Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
64-
6565
public function propertyConsonant(string $propertyName, string ...$additionalChars): Chain;
6666

6767
public function propertyContains(string $propertyName, mixed $containsValue, bool $identical = false): Chain;

library/Mixins/UndefOrBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public static function undefOrCallback(callable $callback, mixed ...$arguments):
5555

5656
public static function undefOrCharset(string $charset, string ...$charsets): Chain;
5757

58+
public static function undefOrCircuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
59+
5860
public static function undefOrCnh(): Chain;
5961

6062
public static function undefOrCnpj(): Chain;
6163

62-
public static function undefOrConsecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
63-
6464
public static function undefOrConsonant(string ...$additionalChars): Chain;
6565

6666
public static function undefOrContains(mixed $containsValue, bool $identical = false): Chain;

library/Mixins/UndefOrChain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public function undefOrCallback(callable $callback, mixed ...$arguments): Chain;
5555

5656
public function undefOrCharset(string $charset, string ...$charsets): Chain;
5757

58+
public function undefOrCircuit(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
59+
5860
public function undefOrCnh(): Chain;
5961

6062
public function undefOrCnpj(): Chain;
6163

62-
public function undefOrConsecutive(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;
63-
6464
public function undefOrConsonant(string ...$additionalChars): Chain;
6565

6666
public function undefOrContains(mixed $containsValue, bool $identical = false): Chain;

library/Rules/Consecutive.php library/Rules/Circuit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Respect\Validation\Rules\Core\Composite;
1616

1717
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
18-
final class Consecutive extends Composite
18+
final class Circuit extends Composite
1919
{
2020
public function evaluate(mixed $input): Result
2121
{

library/Rules/Domain.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function evaluate(mixed $input): Result
5858
return new Result($this->partsRule->evaluate($parts)->isValid, $input, $this);
5959
}
6060

61-
private function createGenericRule(): Consecutive
61+
private function createGenericRule(): Circuit
6262
{
63-
return new Consecutive(
63+
return new Circuit(
6464
new StringType(),
6565
new NoWhitespace(),
6666
new Contains('.'),
@@ -74,13 +74,13 @@ private function createTldRule(bool $realTldCheck): Rule
7474
return new Tld();
7575
}
7676

77-
return new Consecutive(new Not(new StartsWith('-')), new Length(new GreaterThanOrEqual(2)));
77+
return new Circuit(new Not(new StartsWith('-')), new Length(new GreaterThanOrEqual(2)));
7878
}
7979

8080
private function createPartsRule(): Rule
8181
{
8282
return new Each(
83-
new Consecutive(
83+
new Circuit(
8484
new Alnum('-'),
8585
new Not(new StartsWith('-')),
8686
new AnyOf(

library/Transformers/DeprecatedKeyValue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function transform(RuleSpec $ruleSpec): RuleSpec
4242

4343
[$comparedKey, $ruleName, $baseKey] = $ruleSpec->arguments;
4444

45-
return new RuleSpec('consecutive', [
45+
return new RuleSpec('circuit', [
4646
new KeyExists($comparedKey),
4747
new KeyExists($baseKey),
4848
new Lazy(

0 commit comments

Comments
 (0)