forked from Respect/Validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstResultStringFormatter.php
More file actions
31 lines (25 loc) · 956 Bytes
/
FirstResultStringFormatter.php
File metadata and controls
31 lines (25 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
namespace Respect\Validation\Message\Formatter;
use Respect\Validation\Message\Renderer;
use Respect\Validation\Message\StringFormatter;
use Respect\Validation\Result;
final readonly class FirstResultStringFormatter implements StringFormatter
{
/** @param array<string|int, mixed> $templates */
public function format(Result $result, Renderer $renderer, array $templates, bool $isRoot = true): string
{
if (!$result->hasCustomTemplate()) {
foreach ($result->children as $child) {
return $this->format($child, $renderer, $templates, false);
}
}
return $renderer->render($result, $templates, $isRoot);
}
}