Skip to content

Commit 7932fe6

Browse files
committed
Merge branch 'develop'
* develop: specify next release CS fix Each not keeping the mapped content
2 parents c021db1 + 91d4fdf commit 7932fe6

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.1.1 - 2024-02-24
4+
5+
### Fixed
6+
7+
- `Innmind\Validation\Each` now returns the validated data instead of the original content
8+
39
## 1.1.0 - 2023-11-22
410

511
### Added

proofs/each.php

+23
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,27 @@ static function($assert, $ints, $strings) {
5252
);
5353
},
5454
);
55+
56+
yield proof(
57+
'Each::of() returns the mapped content',
58+
given(
59+
Set\Sequence::of(Set\Integers::any()),
60+
),
61+
static function($assert, $ints) {
62+
$doubles = \array_map(
63+
static fn($i) => $i * 2,
64+
$ints,
65+
);
66+
67+
$assert->same(
68+
$doubles,
69+
Each::of(
70+
Is::int()->map(static fn($i) => $i * 2),
71+
)($ints)->match(
72+
static fn($value) => $value,
73+
static fn() => null,
74+
),
75+
);
76+
},
77+
);
5578
};

proofs/instance.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
'Instance::of()',
1010
given(Set\Type::any()),
1111
static function($assert, $other) {
12-
$std = new \stdClass;
12+
$std = new stdClass;
1313
$assert->true(
14-
Instance::of(\stdClass::class)->asPredicate()($std),
14+
Instance::of(stdClass::class)->asPredicate()($std),
1515
);
1616
$assert->same(
1717
$std,
18-
Instance::of(\stdClass::class)($std)->match(
18+
Instance::of(stdClass::class)($std)->match(
1919
static fn($value) => $value,
2020
static fn() => null,
2121
),
2222
);
2323
$assert->false(
24-
Instance::of(\stdClass::class)->asPredicate()($other),
24+
Instance::of(stdClass::class)->asPredicate()($other),
2525
);
2626
$assert->same(
2727
[['$', 'Value is not an instance of stdClass']],
28-
Instance::of(\stdClass::class)($other)->match(
28+
Instance::of(stdClass::class)($other)->match(
2929
static fn() => null,
3030
static fn($failures) => $failures
3131
->map(static fn($failure) => [

proofs/is.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
true,
1717
false,
1818
null,
19-
new \stdClass,
19+
new stdClass,
2020
),
2121
Set\Sequence::of(Set\Strings::any()),
2222
),
@@ -61,7 +61,7 @@ static function($assert, $string, $other) {
6161
true,
6262
false,
6363
null,
64-
new \stdClass,
64+
new stdClass,
6565
),
6666
Set\Sequence::of(Set\Strings::any()),
6767
),
@@ -106,7 +106,7 @@ static function($assert, $int, $other) {
106106
true,
107107
false,
108108
null,
109-
new \stdClass,
109+
new stdClass,
110110
),
111111
Set\Sequence::of(Set\Strings::any()),
112112
),
@@ -152,7 +152,7 @@ static function($assert, $float, $other) {
152152
true,
153153
false,
154154
null,
155-
new \stdClass,
155+
new stdClass,
156156
),
157157
)),
158158
Set\Composite::immutable(
@@ -175,7 +175,7 @@ static function($assert, $float, $other) {
175175
true,
176176
false,
177177
null,
178-
new \stdClass,
178+
new stdClass,
179179
),
180180
),
181181
),
@@ -218,7 +218,7 @@ static function($assert, $array, $other) {
218218
Set\RealNumbers::any(),
219219
Set\Elements::of(
220220
null,
221-
new \stdClass,
221+
new stdClass,
222222
),
223223
Set\Sequence::of(Set\Either::any(
224224
Set\Strings::any(),
@@ -228,7 +228,7 @@ static function($assert, $array, $other) {
228228
true,
229229
false,
230230
null,
231-
new \stdClass,
231+
new stdClass,
232232
),
233233
)),
234234
),
@@ -272,7 +272,7 @@ static function($assert, $bool, $other) {
272272
Set\Elements::of(
273273
true,
274274
false,
275-
new \stdClass,
275+
new stdClass,
276276
),
277277
Set\Sequence::of(Set\Either::any(
278278
Set\Strings::any(),
@@ -282,7 +282,7 @@ static function($assert, $bool, $other) {
282282
true,
283283
false,
284284
null,
285-
new \stdClass,
285+
new stdClass,
286286
),
287287
)),
288288
),
@@ -326,7 +326,7 @@ static function($assert, $other) {
326326
true,
327327
false,
328328
null,
329-
new \stdClass,
329+
new stdClass,
330330
),
331331
)),
332332
Set\Composite::immutable(

src/Each.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ private function __construct(Constraint $constraint)
2929
public function __invoke(mixed $value): Validation
3030
{
3131
/** @var Validation<Failure, list<T>> */
32-
$validation = Validation::success($value);
32+
$validation = Validation::success([]);
3333

3434
/** @var mixed $element */
3535
foreach ($value as $element) {
3636
$validation = $validation->flatMap(
37-
fn($value) => ($this->constraint)($element)->map(
38-
static fn() => $value,
37+
fn($carry) => ($this->constraint)($element)->map(
38+
static fn($value) => \array_merge($carry, [$value]),
3939
),
4040
);
4141
}

0 commit comments

Comments
 (0)