mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01:00
This commit addresses the skipped tests by modifying certain core concepts in the library. The way names work has always been somewhat confusing, even to me. I’ve established that existing names will never be overwritten, and if a path is already defined, we will change the name to also include the path. I’m not very happy with how I’m solving this problem, because the `FirstResultStringFormatter` is changing some behaviour in the results that seems to be something that should always happen before. But, for the moment, I will keep it as is.
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Message\Formatter;
|
|
|
|
use Respect\Validation\Message\Renderer;
|
|
use Respect\Validation\Message\StringFormatter;
|
|
use Respect\Validation\Name;
|
|
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): string
|
|
{
|
|
return $this->formatResult($result, $renderer, $templates, null);
|
|
}
|
|
|
|
/** @param array<string|int, mixed> $templates */
|
|
private function formatResult(Result $result, Renderer $renderer, array $templates, Name|null $parentName): string
|
|
{
|
|
if (!$result->hasCustomTemplate()) {
|
|
foreach ($result->children as $child) {
|
|
return $this->formatResult($child, $renderer, $templates, $result->name ?? $parentName);
|
|
}
|
|
}
|
|
|
|
if ($parentName !== null) {
|
|
$result = $result->withName($parentName);
|
|
}
|
|
|
|
return $renderer->render($result, $templates);
|
|
}
|
|
}
|