@@ -16,4 +16,59 @@ enum Operator: string
1616 case LESS_THAN_OR_EQUAL = '<= ' ;
1717 case GREATER_THAN_OR_EQUAL = '>= ' ;
1818 case SPACESHIP = '<=> ' ;
19+
20+ public function compare (mixed $ left , mixed $ right ): bool |int
21+ {
22+ return self ::{'compare_ ' .$ this ->name }($ left , $ right );
23+ }
24+
25+ private static function compare_EQUAL (mixed $ left , mixed $ right ): bool
26+ {
27+ return $ left == $ right ;
28+ }
29+
30+ private static function compare_IDENTICAL (mixed $ left , mixed $ right ): bool
31+ {
32+ return $ left === $ right ;
33+ }
34+
35+ private static function compare_NOT_EQUAL (mixed $ left , mixed $ right ): bool
36+ {
37+ return $ left != $ right ;
38+ }
39+
40+ private static function compare_NOT_EQUAL_DIAMOND (mixed $ left , mixed $ right ): bool
41+ {
42+ return self ::compare_NOT_EQUAL ($ left , $ right );
43+ }
44+
45+ private static function compare_NOT_IDENTICAL (mixed $ left , mixed $ right ): bool
46+ {
47+ return $ left !== $ right ;
48+ }
49+
50+ private static function compare_LESS_THAN (mixed $ left , mixed $ right ): bool
51+ {
52+ return $ left < $ right ;
53+ }
54+
55+ private static function compare_GREATER_THAN (mixed $ left , mixed $ right ): bool
56+ {
57+ return $ left > $ right ;
58+ }
59+
60+ private static function compare_LESS_THAN_OR_EQUAL (mixed $ left , mixed $ right ): bool
61+ {
62+ return $ left <= $ right ;
63+ }
64+
65+ private static function compare_GREATER_THAN_OR_EQUAL (mixed $ left , mixed $ right ): bool
66+ {
67+ return $ left >= $ right ;
68+ }
69+
70+ private static function compare_SPACESHIP (mixed $ left , mixed $ right ): int
71+ {
72+ return $ left <=> $ right ;
73+ }
1974}
0 commit comments