Skip to content

Commit dcea800

Browse files
committed
Build additional error description statelessly
1 parent f3fedcc commit dcea800

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Constraint/JsonValueMatchesMany.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class JsonValueMatchesMany extends Constraint
1717
/** @var JsonValueMatches[] */
1818
private $constraints = array();
1919

20-
/** @var string[] */
21-
private $failedConstraints = array();
22-
2320
/**
2421
* JsonValueMatchesMany constructor.
2522
*
@@ -62,14 +59,12 @@ function (Constraint $constraint) {
6259
*/
6360
protected function matches($other): bool
6461
{
65-
$result = true;
6662
foreach ($this->constraints as $constraint) {
6763
if (!$constraint->evaluate($other, '', true)) {
68-
$result = false;
69-
$this->failedConstraints[] = $constraint->toString();
64+
return false;
7065
}
7166
}
72-
return $result;
67+
return true;
7368
}
7469

7570
/**
@@ -79,6 +74,15 @@ protected function matches($other): bool
7974
*/
8075
protected function additionalFailureDescription($other): string
8176
{
82-
return "\n" . implode("\n", $this->failedConstraints);
77+
/** @var string[] */
78+
$failedConstraints = array();
79+
80+
foreach ($this->constraints as $constraint) {
81+
if (!$constraint->evaluate($other, '', true)) {
82+
$failedConstraints[] = $constraint->toString();
83+
}
84+
}
85+
86+
return "\n" . implode("\n", $failedConstraints);
8387
}
8488
}

0 commit comments

Comments
 (0)