Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Dec 27, 2024
1 parent ae48959 commit 2ca49bb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
12 changes: 11 additions & 1 deletion library/Message/StandardFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ public function full(

$rendered = '';
if ($this->isAlwaysVisible($result, ...$siblings) || $isFinalTemplate) {
if ($parent && $parent->path !== null && $result->path !== null && $result->path !== $parent->path) {
$result = $result->withPath($parent->path);
} elseif ($parent && $parent->path !== null && $result->path === null) {
$result = $result->withPath($parent->path);
}
$resultToRender = $result;
if ($depth > 0 && $result->path !== null) {
$paths = explode('.', (string) $result->path);
$resultToRender->path = end($paths);
}
$indentation = str_repeat(' ', $depth * 2);
$rendered .= sprintf(
'%s- %s' . PHP_EOL,
$indentation,
$this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator),
$this->renderer->render($this->getTemplated($resultToRender, $selectedTemplates), $translator),
);
$depth++;
}
Expand Down
2 changes: 1 addition & 1 deletion library/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
public readonly ?string $name = null,
?string $id = null,
public readonly ?Result $adjacent = null,
public readonly string|int|null $path = null,
public string|int|null $path = null,
Result ...$children,
) {
$this->id = $id ?? lcfirst(substr((string) strrchr($rule::class, '\\'), 1));
Expand Down
8 changes: 4 additions & 4 deletions tests/feature/Issues/Issue1289Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
<<<'FULL_MESSAGE'
- `.0` must pass the rules
- `.default` must pass one of the rules
- 2 must be a string
- 2 must be a boolean
- `.default` be a string
- `.default` be a boolean
- `.description` must be a string value
FULL_MESSAGE,
[
0 => [
'__root__' => '`.0` must pass the rules',
'default' => [
'__root__' => '`.default` must pass one of the rules',
'stringType' => '2 must be a string',
'boolType' => '2 must be a boolean',
'stringType' => '`.default` be a string',
'boolType' => '`.default` be a boolean',
],
'description' => '`.description` must be a string value',
],
Expand Down
12 changes: 6 additions & 6 deletions tests/feature/Issues/Issue1334Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ function (): void {
- `.0` must pass the rules
- `.street` must be present
- `.other` must pass the rules
- 123 must be a string or must be null
- `.other` must be a string or must be null
- `.1` must pass the rules
- "" must not be empty
- `.street` must not be empty
- `.2` must pass the rules
- 123 must be a string
- `.street` must be a string
FULL_MESSAGE,
[
'each' => [
'__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
0 => [
'__root__' => '`.0` must pass the rules',
'street' => '`.street` must be present',
'other' => '123 must be a string or must be null',
'other' => '`.other` must be a string or must be null',
],
1 => '"" must not be empty',
2 => '123 must be a string',
1 => '`.street` must not be empty',
2 => '`.street` must be a string',
],
],
));
10 changes: 5 additions & 5 deletions tests/feature/Rules/EachTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@
FULL_MESSAGE,
[
'__root__' => 'Each item in `[["not_int": "wrong"], ["my_int": 2], "not an array"]` must be valid',
0 => 'my_int must be present',
1 => 'my_int must be an odd number',
0 => '`.my_int` must be present',
1 => '`.my_int` must be an odd number',
2 => [
'__root__' => '"not an array" must pass all the rules',
'arrayType' => '"not an array" must be an array',
'my_int' => 'my_int must be present',
'__root__' => '`.2` must pass all the rules',
'arrayType' => '`.2` must be an array',
'my_int' => '`.my_int` must be present',
],
],
));

0 comments on commit 2ca49bb

Please sign in to comment.