Skip to content

Commit 2ca49bb

Browse files
committed
v2
1 parent ae48959 commit 2ca49bb

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

library/Message/StandardFormatter.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,21 @@ public function full(
7171

7272
$rendered = '';
7373
if ($this->isAlwaysVisible($result, ...$siblings) || $isFinalTemplate) {
74+
if ($parent && $parent->path !== null && $result->path !== null && $result->path !== $parent->path) {
75+
$result = $result->withPath($parent->path);
76+
} elseif ($parent && $parent->path !== null && $result->path === null) {
77+
$result = $result->withPath($parent->path);
78+
}
79+
$resultToRender = $result;
80+
if ($depth > 0 && $result->path !== null) {
81+
$paths = explode('.', (string) $result->path);
82+
$resultToRender->path = end($paths);
83+
}
7484
$indentation = str_repeat(' ', $depth * 2);
7585
$rendered .= sprintf(
7686
'%s- %s' . PHP_EOL,
7787
$indentation,
78-
$this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator),
88+
$this->renderer->render($this->getTemplated($resultToRender, $selectedTemplates), $translator),
7989
);
8090
$depth++;
8191
}

library/Result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
public readonly ?string $name = null,
4040
?string $id = null,
4141
public readonly ?Result $adjacent = null,
42-
public readonly string|int|null $path = null,
42+
public string|int|null $path = null,
4343
Result ...$children,
4444
) {
4545
$this->id = $id ?? lcfirst(substr((string) strrchr($rule::class, '\\'), 1));

tests/feature/Issues/Issue1289Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@
4949
<<<'FULL_MESSAGE'
5050
- `.0` must pass the rules
5151
- `.default` must pass one of the rules
52-
- 2 must be a string
53-
- 2 must be a boolean
52+
- `.default` be a string
53+
- `.default` be a boolean
5454
- `.description` must be a string value
5555
FULL_MESSAGE,
5656
[
5757
0 => [
5858
'__root__' => '`.0` must pass the rules',
5959
'default' => [
6060
'__root__' => '`.default` must pass one of the rules',
61-
'stringType' => '2 must be a string',
62-
'boolType' => '2 must be a boolean',
61+
'stringType' => '`.default` be a string',
62+
'boolType' => '`.default` be a boolean',
6363
],
6464
'description' => '`.description` must be a string value',
6565
],

tests/feature/Issues/Issue1334Test.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ function (): void {
2828
- `.0` must pass the rules
2929
- `.street` must be present
3030
- `.other` must pass the rules
31-
- 123 must be a string or must be null
31+
- `.other` must be a string or must be null
3232
- `.1` must pass the rules
33-
- "" must not be empty
33+
- `.street` must not be empty
3434
- `.2` must pass the rules
35-
- 123 must be a string
35+
- `.street` must be a string
3636
FULL_MESSAGE,
3737
[
3838
'each' => [
3939
'__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
4040
0 => [
4141
'__root__' => '`.0` must pass the rules',
4242
'street' => '`.street` must be present',
43-
'other' => '123 must be a string or must be null',
43+
'other' => '`.other` must be a string or must be null',
4444
],
45-
1 => '"" must not be empty',
46-
2 => '123 must be a string',
45+
1 => '`.street` must not be empty',
46+
2 => '`.street` must be a string',
4747
],
4848
],
4949
));

tests/feature/Rules/EachTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@
282282
FULL_MESSAGE,
283283
[
284284
'__root__' => 'Each item in `[["not_int": "wrong"], ["my_int": 2], "not an array"]` must be valid',
285-
0 => 'my_int must be present',
286-
1 => 'my_int must be an odd number',
285+
0 => '`.my_int` must be present',
286+
1 => '`.my_int` must be an odd number',
287287
2 => [
288-
'__root__' => '"not an array" must pass all the rules',
289-
'arrayType' => '"not an array" must be an array',
290-
'my_int' => 'my_int must be present',
288+
'__root__' => '`.2` must pass all the rules',
289+
'arrayType' => '`.2` must be an array',
290+
'my_int' => '`.my_int` must be present',
291291
],
292292
],
293293
));

0 commit comments

Comments
 (0)