diff --git a/src/Message/Formatter/NestedListStringFormatter.php b/src/Message/Formatter/NestedListStringFormatter.php index c303b9f8..3a9d5783 100644 --- a/src/Message/Formatter/NestedListStringFormatter.php +++ b/src/Message/Formatter/NestedListStringFormatter.php @@ -17,7 +17,6 @@ use Respect\Validation\Name; use Respect\Validation\Result; use function array_filter; -use function array_reduce; use function count; use function rtrim; use function sprintf; @@ -89,13 +88,14 @@ final readonly class NestedListStringFormatter implements StringFormatter } // The visibility of a result then will depend on whether any of its siblings is visible - return array_reduce( - $siblings, - fn(bool $carry, Result $currentSibling) => $carry || $this->isVisible( - $currentSibling, - ...array_filter($siblings, static fn(Result $sibling) => $sibling !== $currentSibling), - ), - true, - ); + foreach ($siblings as $key => $currentSibling) { + $otherSiblings = $siblings; + unset($otherSiblings[$key]); + if ($this->isVisible($currentSibling, ...$otherSiblings)) { + return true; + } + } + + return false; } } diff --git a/tests/feature/AssertWithPropertiesTest.php b/tests/feature/AssertWithPropertiesTest.php index b0fefdfe..224d6460 100644 --- a/tests/feature/AssertWithPropertiesTest.php +++ b/tests/feature/AssertWithPropertiesTest.php @@ -43,9 +43,7 @@ test('Scenario #1', catchFullMessage( ]))), fn(string $fullMessage) => expect($fullMessage)->toBe(<<<'FULL_MESSAGE' - the given data must pass all the rules - - `.mysql` must pass the rules - - `.mysql.host` must be a string - - `.postgresql` must pass the rules - - `.postgresql.user` must be a string + - `.mysql.host` must be a string + - `.postgresql.user` must be a string FULL_MESSAGE), )); diff --git a/tests/feature/Issues/Issue796Test.php b/tests/feature/Issues/Issue796Test.php index 81120614..50badf5e 100644 --- a/tests/feature/Issues/Issue796Test.php +++ b/tests/feature/Issues/Issue796Test.php @@ -46,10 +46,8 @@ test('https://github.com/Respect/Validation/issues/796', catchAll( ->and($message)->toBe('`.mysql.host` (<- the given data) must be a string') ->and($fullMessage)->toBe(<<<'FULL_MESSAGE' - the given data must pass all the rules - - `.mysql` must pass the rules - - `.mysql.host` must be a string - - `.postgresql` must pass the rules - - `.postgresql.user` must be a string + - `.mysql.host` must be a string + - `.postgresql.user` must be a string FULL_MESSAGE) ->and($messages)->toBe([ '__root__' => 'the given data must pass all the rules',