Skip to content

Commit f60479f

Browse files
committed
PR review changes
1 parent 102c44b commit f60479f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/Http/Validator/AllOf.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
class AllOf extends Validator
1313
{
14+
protected ?Validator $failedRule = null;
15+
1416
/**
1517
* @param array<Validator> $validators
1618
*/
@@ -28,8 +30,9 @@ public function __construct(protected array $validators, protected string $type
2830
public function getDescription(): string
2931
{
3032
$description = '';
31-
foreach ($this->validators as $key => $rule) {
32-
$description .= ++$key . '. ' . $rule->getDescription() . " \n";
33+
34+
if(!(\is_null($this->failedRule))) {
35+
$description .= $this->failedRule->getDescription();
3336
}
3437

3538
return $description;
@@ -49,6 +52,7 @@ public function isValid(mixed $value): bool
4952
$valid = $rule->isValid($value);
5053

5154
if(!$valid) {
55+
$this->failedRule = $rule;
5256
return false;
5357
}
5458
}

src/Http/Validator/AnyOf.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
class AnyOf extends Validator
1313
{
14+
protected ?Validator $failedRule = null;
15+
1416
/**
1517
* @param array<Validator> $validators
1618
*/
@@ -28,8 +30,9 @@ public function __construct(protected array $validators, protected string $type
2830
public function getDescription(): string
2931
{
3032
$description = '';
31-
foreach ($this->validators as $key => $rule) {
32-
$description .= ++$key . '. ' . $rule->getDescription() . " \n";
33+
34+
if(!(\is_null($this->failedRule))) {
35+
$description .= $this->failedRule->getDescription();
3336
}
3437

3538
return $description;
@@ -48,6 +51,8 @@ public function isValid(mixed $value): bool
4851
foreach ($this->validators as $rule) {
4952
$valid = $rule->isValid($value);
5053

54+
$this->failedRule = $rule;
55+
5156
if($valid) {
5257
return true;
5358
}

src/Http/Validator/NoneOf.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
class NoneOf extends Validator
1313
{
14+
protected ?Validator $failedRule = null;
15+
1416
/**
1517
* @param array<Validator> $validators
1618
*/
@@ -28,8 +30,9 @@ public function __construct(protected array $validators, protected string $type
2830
public function getDescription(): string
2931
{
3032
$description = '';
31-
foreach ($this->validators as $key => $rule) {
32-
$description .= ++$key . '. ' . $rule->getDescription() . " \n";
33+
34+
if(!(\is_null($this->failedRule))) {
35+
$description .= $this->failedRule->getDescription();
3336
}
3437

3538
return $description;
@@ -49,6 +52,7 @@ public function isValid(mixed $value): bool
4952
$valid = $rule->isValid($value);
5053

5154
if($valid) {
55+
$this->failedRule = $rule;
5256
return false;
5357
}
5458
}

0 commit comments

Comments
 (0)