This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +11
-9
lines changed
Expand file tree Collapse file tree 3 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 55use ProgrammatorDev \YetAnotherPhpValidator \Exception \AllException ;
66use ProgrammatorDev \YetAnotherPhpValidator \Exception \UnexpectedValueException ;
77use ProgrammatorDev \YetAnotherPhpValidator \Exception \ValidationException ;
8- use ProgrammatorDev \YetAnotherPhpValidator \Rule \Util \AssertIsValidatableTrait ;
8+ use ProgrammatorDev \YetAnotherPhpValidator \Rule \Util \IsValidatableTrait ;
99use Symfony \Component \OptionsResolver \OptionsResolver ;
1010
1111class All extends AbstractRule implements RuleInterface
1212{
13- use AssertIsValidatableTrait ;
13+ use IsValidatableTrait ;
1414
1515 private array $ options ;
1616
@@ -33,7 +33,11 @@ public function __construct(
3333
3434 public function assert (mixed $ value , string $ name ): void
3535 {
36- $ this ->assertIsValidatable ($ this ->constraints );
36+ if (!$ this ->isValidatable ($ this ->constraints )) {
37+ throw new UnexpectedValueException (
38+ 'All constraints must be of type "RuleInterface". '
39+ );
40+ }
3741
3842 if (!\is_array ($ value )) {
3943 throw new UnexpectedValueException (
Original file line number Diff line number Diff line change 55use ProgrammatorDev \YetAnotherPhpValidator \Exception \UnexpectedValueException ;
66use ProgrammatorDev \YetAnotherPhpValidator \Rule \RuleInterface ;
77
8- trait AssertIsValidatableTrait
8+ trait IsValidatableTrait
99{
10- private function assertIsValidatable (array $ constraints ): bool
10+ private function isValidatable (array $ constraints ): bool
1111 {
1212 foreach ($ constraints as $ constraint ) {
1313 if (!$ constraint instanceof RuleInterface) {
14- throw new UnexpectedValueException (
15- \sprintf ('Expected constraint of type "RuleInterface", "%s" given. ' , get_debug_type ($ constraint ))
16- );
14+ return false ;
1715 }
1816 }
1917
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public static function provideRuleUnexpectedValueData(): \Generator
2424 yield 'invalid constraint ' => [
2525 new All ([new NotBlank (), 'invalid ' ]),
2626 [1 , 2 , 3 ],
27- '/Expected constraint of type "RuleInterface", "(.*)" given ./ '
27+ '/All constraints must be of type "RuleInterface"./ '
2828 ];
2929 yield 'invalid value type ' => [
3030 new All ([new NotBlank ()]),
You can’t perform that action at this time.
0 commit comments