Skip to content

Commit b894593

Browse files
committed
Rename "negative" to "inverted" mode
The original name was heavily influenced by the fact that we get those messages when using the "Not" rule; however, that rule inverts the validation despite the current validation mode. It can be confusing at times with certain rules, so naming it as "inverted" makes more sense than "negative".
1 parent 2aa5e39 commit b894593

23 files changed

+128
-128
lines changed

library/Message/StandardRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ private function getTemplateMessage(Result $result): string
9494
continue;
9595
}
9696

97-
if ($result->mode == Mode::NEGATIVE) {
98-
return $template->negative;
97+
if ($result->mode == Mode::INVERTED) {
98+
return $template->inverted;
9999
}
100100

101101
return $template->default;

library/Message/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class Template
1717
{
1818
public function __construct(
1919
public readonly string $default,
20-
public readonly string $negative,
20+
public readonly string $inverted,
2121
public readonly string $id = Validatable::TEMPLATE_STANDARD,
2222
) {
2323
}

library/Mode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
enum Mode
1313
{
1414
case DEFAULT;
15-
case NEGATIVE;
15+
case INVERTED;
1616
}

library/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function withInvertedMode(): self
122122
{
123123
return $this->clone(
124124
isValid: !$this->isValid,
125-
mode: $this->mode == Mode::DEFAULT ? Mode::NEGATIVE : Mode::DEFAULT,
125+
mode: $this->mode == Mode::DEFAULT ? Mode::INVERTED : Mode::DEFAULT,
126126
nextSibling: $this->nextSibling?->withInvertedMode(),
127127
children: array_map(static fn (Result $child) => $child->withInvertedMode(), $this->children),
128128
);

tests/integration/rules/betweenExclusive.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'vendor/autoload.php';
55

66
run([
77
'Default' => [v::betweenExclusive(1, 10), 12],
8-
'Negative' => [v::not(v::betweenExclusive(1, 10)), 5],
8+
'Inverted' => [v::not(v::betweenExclusive(1, 10)), 5],
99
'With template' => [v::betweenExclusive(1, 10), 12, 'Bewildered bees buzzed between blooming begonias'],
1010
'With name' => [v::betweenExclusive(1, 10)->setName('Range'), 10],
1111
]);
@@ -19,7 +19,7 @@ Default
1919
'betweenExclusive' => '12 must be greater than 1 and less than 10',
2020
]
2121

22-
Negative
22+
Inverted
2323
⎺⎺⎺⎺⎺⎺⎺⎺
2424
5 must not be greater than 1 and less than 10
2525
- 5 must not be greater than 1 and less than 10

tests/integration/rules/consecutive.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'vendor/autoload.php';
55

66
run([
77
'Default' => [v::consecutive(v::alwaysValid(), v::trueVal()), false],
8-
'Negative' => [v::not(v::consecutive(v::alwaysValid(), v::trueVal())), true],
8+
'Inverted' => [v::not(v::consecutive(v::alwaysValid(), v::trueVal())), true],
99
'Default with inverted failing rule' => [v::consecutive(v::alwaysValid(), v::not(v::trueVal())), true],
1010
'With wrapped name, default' => [
1111
v::consecutive(v::alwaysValid(), v::trueVal()->setName('Wrapped'))->setName('Wrapper'),
@@ -58,7 +58,7 @@ Default
5858
'trueVal' => '`false` must evaluate to `true`',
5959
]
6060

61-
Negative
61+
Inverted
6262
⎺⎺⎺⎺⎺⎺⎺⎺
6363
`true` must not evaluate to `true`
6464
- `true` must not evaluate to `true`

tests/integration/rules/each.phpt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ require 'vendor/autoload.php';
55

66
$empty = [];
77
$nonIterable = null;
8-
$negative = [1, 2, 3];
8+
$inverted = [1, 2, 3];
99
$default = ['a', 'b', 'c'];
1010

1111
run([
1212
// Simple
1313
'Non-iterable' => [v::each(v::intType()), $nonIterable],
1414
'Empty' => [v::each(v::intType()), $empty],
1515
'Default' => [v::each(v::intType()), $default],
16-
'Negative' => [v::not(v::each(v::intType())), $negative],
16+
'Inverted' => [v::not(v::each(v::intType())), $inverted],
1717

1818
// With name
1919
'With name, non-iterable' => [v::each(v::intType()->setName('Wrapped'))->setName('Wrapper'), $nonIterable],
2020
'With name, empty' => [v::each(v::intType()->setName('Wrapped'))->setName('Wrapper'), $empty],
2121
'With name, default' => [v::each(v::intType()->setName('Wrapped'))->setName('Wrapper'), $default],
22-
'With name, negative' => [
22+
'With name, inverted' => [
2323
v::not(v::each(v::intType()->setName('Wrapped'))->setName('Wrapper'))->setName('Not'),
24-
$negative,
24+
$inverted,
2525
],
2626
'With wrapper name, default' => [v::each(v::intType())->setName('Wrapper'), $default],
27-
'With wrapper name, negative' => [
27+
'With wrapper name, inverted' => [
2828
v::not(v::each(v::intType())->setName('Wrapper'))->setName('Not'),
29-
$negative,
29+
$inverted,
3030
],
31-
'With Not name, negative' => [
31+
'With Not name, inverted' => [
3232
v::not(v::each(v::intType()))->setName('Not'),
33-
$negative,
33+
$inverted,
3434
],
3535

3636
// With template
3737
'With template, non-iterable' => [v::each(v::intType()), $nonIterable, 'You should have passed an iterable'],
3838
'With template, empty' => [v::each(v::intType()), $empty, 'You should have passed an non-empty'],
3939
'With template, default' => [v::each(v::intType()), $default, 'All items should have been integers'],
40-
'with template, negative' => [v::not(v::each(v::intType())), $negative, 'All items should not have been integers'],
40+
'with template, inverted' => [v::not(v::each(v::intType())), $inverted, 'All items should not have been integers'],
4141

4242
// With array template
4343
'With array template, default' => [
@@ -95,7 +95,7 @@ Default
9595
'intType.3' => '"c" must be of type integer',
9696
]
9797

98-
Negative
98+
Inverted
9999
⎺⎺⎺⎺⎺⎺⎺⎺
100100
1 must not be of type integer
101101
- Each item in `[1, 2, 3]` must not validate
@@ -139,7 +139,7 @@ Wrapped must be of type integer
139139
'intType.3' => 'Wrapped must be of type integer',
140140
]
141141

142-
With name, negative
142+
With name, inverted
143143
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
144144
Wrapped must not be of type integer
145145
- Each item in Wrapped must not validate
@@ -167,7 +167,7 @@ Wrapper must be of type integer
167167
'intType.3' => 'Wrapper must be of type integer',
168168
]
169169

170-
With wrapper name, negative
170+
With wrapper name, inverted
171171
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
172172
Wrapper must not be of type integer
173173
- Each item in Wrapper must not validate
@@ -181,7 +181,7 @@ Wrapper must not be of type integer
181181
'intType.3' => 'Wrapper must not be of type integer',
182182
]
183183

184-
With Not name, negative
184+
With Not name, inverted
185185
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
186186
Not must not be of type integer
187187
- Each item in Not must not validate
@@ -219,7 +219,7 @@ All items should have been integers
219219
'each' => 'All items should have been integers',
220220
]
221221

222-
with template, negative
222+
with template, inverted
223223
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
224224
All items should not have been integers
225225
- All items should not have been integers

tests/integration/rules/hetu.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'vendor/autoload.php';
55

66
run([
77
'Default' => [v::hetu(), '010106A901O'],
8-
'Negative' => [v::not(v::hetu()), '010106A9012'],
8+
'Inverted' => [v::not(v::hetu()), '010106A9012'],
99
'With template' => [v::hetu(), '010106A901O', 'That is not a HETU'],
1010
'With name' => [v::hetu()->setName('Hetu'), '010106A901O'],
1111
]);
@@ -19,7 +19,7 @@ Default
1919
'hetu' => '"010106A901O" must be a valid Finnish personal identity code',
2020
]
2121

22-
Negative
22+
Inverted
2323
⎺⎺⎺⎺⎺⎺⎺⎺
2424
"010106A9012" must not be a valid Finnish personal identity code
2525
- "010106A9012" must not be a valid Finnish personal identity code

tests/integration/rules/iterableType.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'vendor/autoload.php';
55

66
run([
77
'Default' => [v::iterableType(), null],
8-
'Negative' => [v::not(v::iterableType()), [1, 2, 3]],
8+
'Inverted' => [v::not(v::iterableType()), [1, 2, 3]],
99
'With template' => [v::iterableType(), null, 'Not an iterable at all'],
1010
'With name' => [v::iterableType()->setName('Options'), null],
1111
]);
@@ -19,7 +19,7 @@ Default
1919
'iterableType' => '`null` must be of type iterable',
2020
]
2121

22-
Negative
22+
Inverted
2323
⎺⎺⎺⎺⎺⎺⎺⎺
2424
`[1, 2, 3]` must not of type iterable
2525
- `[1, 2, 3]` must not of type iterable

tests/integration/rules/key.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ run([
77
// Simple
88
'Missing key' => [v::key('foo', v::intType()), []],
99
'Default' => [v::key('foo', v::intType()), ['foo' => 'string']],
10-
'Negative' => [v::not(v::key('foo', v::intType())), ['foo' => 12]],
11-
'Double-negative with missing key' => [
10+
'Inverted' => [v::not(v::key('foo', v::intType())), ['foo' => 12]],
11+
'Double-inverted with missing key' => [
1212
v::not(v::not(v::key('foo', v::intType()))),
1313
[],
1414
],
@@ -22,7 +22,7 @@ run([
2222
v::key('foo', v::intType()->setName('Wrapped'))->setName('Wrapper'),
2323
['foo' => 'string'],
2424
],
25-
'With wrapped name, negative' => [
25+
'With wrapped name, inverted' => [
2626
v::not(v::key('foo', v::intType()->setName('Wrapped'))->setName('Wrapper'))->setName('Not'),
2727
['foo' => 12],
2828
],
@@ -34,18 +34,18 @@ run([
3434
v::key('foo', v::intType())->setName('Wrapper'),
3535
[],
3636
],
37-
'With wrapper name, negative' => [
37+
'With wrapper name, inverted' => [
3838
v::not(v::key('foo', v::intType())->setName('Wrapper'))->setName('Not'),
3939
['foo' => 12],
4040
],
41-
'With "Not" name, negative' => [
41+
'With "Not" name, inverted' => [
4242
v::not(v::key('foo', v::intType()))->setName('Not'),
4343
['foo' => 12],
4444
],
4545

4646
// With custom template
4747
'With template, default' => [v::key('foo', v::intType()), ['foo' => 'string'], 'That key is off-key'],
48-
'With template, negative' => [v::not(v::key('foo', v::intType())), ['foo' => 12], 'No off-key key'],
48+
'With template, inverted' => [v::not(v::key('foo', v::intType())), ['foo' => 12], 'No off-key key'],
4949
]);
5050
?>
5151
--EXPECT--
@@ -65,15 +65,15 @@ foo must be of type integer
6565
'foo' => 'foo must be of type integer',
6666
]
6767

68-
Negative
68+
Inverted
6969
⎺⎺⎺⎺⎺⎺⎺⎺
7070
foo must not be of type integer
7171
- foo must not be of type integer
7272
[
7373
'foo' => 'foo must not be of type integer',
7474
]
7575

76-
Double-negative with missing key
76+
Double-inverted with missing key
7777
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
7878
foo must be present
7979
- foo must be present
@@ -97,7 +97,7 @@ Wrapped must be of type integer
9797
'foo' => 'Wrapped must be of type integer',
9898
]
9999

100-
With wrapped name, negative
100+
With wrapped name, inverted
101101
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
102102
Wrapped must not be of type integer
103103
- Wrapped must not be of type integer
@@ -121,15 +121,15 @@ foo must be present
121121
'foo' => 'foo must be present',
122122
]
123123

124-
With wrapper name, negative
124+
With wrapper name, inverted
125125
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
126126
foo must not be of type integer
127127
- foo must not be of type integer
128128
[
129129
'foo' => 'foo must not be of type integer',
130130
]
131131

132-
With "Not" name, negative
132+
With "Not" name, inverted
133133
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
134134
foo must not be of type integer
135135
- foo must not be of type integer
@@ -145,7 +145,7 @@ That key is off-key
145145
'foo' => 'That key is off-key',
146146
]
147147

148-
With template, negative
148+
With template, inverted
149149
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
150150
No off-key key
151151
- No off-key key

0 commit comments

Comments
 (0)