22
33namespace ProgrammatorDev \YetAnotherPhpValidator \Rule ;
44
5- use ProgrammatorDev \YetAnotherPhpValidator \Exception \GreaterThanException ;
65use ProgrammatorDev \YetAnotherPhpValidator \Exception \GreaterThanOrEqualException ;
7- use ProgrammatorDev \YetAnotherPhpValidator \Exception \UnexpectedComparableException ;
8- use ProgrammatorDev \YetAnotherPhpValidator \Rule \Util \ComparableTrait ;
96use Symfony \Component \OptionsResolver \OptionsResolver ;
107
11- class GreaterThanOrEqual extends AbstractRule implements RuleInterface
8+ class GreaterThanOrEqual extends AbstractComparisonRule implements RuleInterface
129{
13- use ComparableTrait ;
10+ protected array $ options ;
1411
15- private array $ options ;
16-
17- public function __construct (private readonly mixed $ constraint , array $ options = [])
12+ public function __construct (
13+ protected readonly mixed $ constraint ,
14+ array $ options = []
15+ )
1816 {
1917 $ resolver = new OptionsResolver ();
2018
@@ -25,30 +23,13 @@ public function __construct(private readonly mixed $constraint, array $options =
2523 $ this ->options = $ resolver ->resolve ($ options );
2624 }
2725
28- /**
29- * @throws GreaterThanOrEqualException
30- */
31- public function assert (mixed $ value , string $ name ): void
26+ protected function comparison (mixed $ constraint , mixed $ value ): bool
27+ {
28+ return $ value >= $ constraint ;
29+ }
30+
31+ protected function getException (): string
3232 {
33- $ constraint = $ this ->convertToComparable ($ this ->constraint );
34- $ value = $ this ->convertToComparable ($ value );
35-
36- if (!$ this ->isComparable ($ constraint , $ value )) {
37- throw new UnexpectedComparableException (
38- get_debug_type ($ constraint ),
39- get_debug_type ($ value )
40- );
41- }
42-
43- if (!($ value >= $ constraint )) {
44- throw new GreaterThanOrEqualException (
45- message: $ this ->options ['message ' ],
46- parameters: [
47- 'value ' => $ value ,
48- 'name ' => $ name ,
49- 'constraint ' => $ constraint
50- ]
51- );
52- }
33+ return GreaterThanOrEqualException::class;
5334 }
5435}
0 commit comments