1 | <?php |
||
22 | final class Comparison |
||
23 | { |
||
24 | const EQUALS = '=='; |
||
25 | const IDENTICAL = '==='; |
||
26 | const NOT_EQUALS = '!='; |
||
27 | const NOT_IDENTICAL = '!=='; |
||
28 | const GREATER_THAN = '>'; |
||
29 | const LESSER_THAN = '<'; |
||
30 | const LESSER_THAN_OR_EQUALS = '<='; |
||
31 | const GREATER_THAN_OR_EQUALS = '>='; |
||
32 | |||
33 | /** |
||
34 | * Operation method mapping cache. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | private static $operators; |
||
39 | |||
40 | /** |
||
41 | * Compare two values. |
||
42 | * |
||
43 | * @param mixed $valueA Value a. |
||
44 | * @param mixed $valueB Value b. |
||
45 | * @param string $operator The operator for the comparison. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public static function compare($valueA, $valueB, string $operator): bool |
||
59 | |||
60 | /** |
||
61 | * Consider if two values equals. |
||
62 | * |
||
63 | * @param mixed $valueA Value a. |
||
64 | * @param mixed $valueB Value b. |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | public static function equals($valueA, $valueB): bool |
||
72 | |||
73 | /** |
||
74 | * Consider if both values are identical. |
||
75 | * |
||
76 | * It uses the === operator of php. |
||
77 | * |
||
78 | * @param mixed $valueA Value a. |
||
79 | * @param mixed $valueB Value b. |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | public static function identical($valueA, $valueB): bool |
||
87 | |||
88 | /** |
||
89 | * Consider if two values not equals. |
||
90 | * |
||
91 | * @param mixed $valueA Value a. |
||
92 | * @param mixed $valueB Value b. |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | public static function notEquals($valueA, $valueB): bool |
||
100 | |||
101 | /** |
||
102 | * Consider if two values are not identical. |
||
103 | * |
||
104 | * @param mixed $valueA Value a. |
||
105 | * @param mixed $valueB Value b. |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public static function notIdentical($valueA, $valueB): bool |
||
113 | |||
114 | /** |
||
115 | * Consider if value a is greater than value b. |
||
116 | * |
||
117 | * @param mixed $valueA Value a. |
||
118 | * @param mixed $valueB Value b. |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public static function greaterThan($valueA, $valueB): bool |
||
126 | |||
127 | /** |
||
128 | * Consider if value a is greater than or equals value b. |
||
129 | * |
||
130 | * @param mixed $valueA Value a. |
||
131 | * @param mixed $valueB Value b. |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | public static function greaterThanOrEquals($valueA, $valueB): bool |
||
139 | |||
140 | /** |
||
141 | * Consider if value a is lesser than value b. |
||
142 | * |
||
143 | * @param mixed $valueA Value a. |
||
144 | * @param mixed $valueB Value b. |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public static function lesserThan($valueA, $valueB): bool |
||
152 | |||
153 | /** |
||
154 | * Consider if value a is lesser than or equals value b. |
||
155 | * |
||
156 | * @param mixed $valueA Value a. |
||
157 | * @param mixed $valueB Value b. |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | public static function lesserThanOrEquals($valueA, $valueB): bool |
||
165 | |||
166 | /** |
||
167 | * Get operator method. Returns false if metod not set. |
||
168 | * |
||
169 | * @param string $operator The current operator. |
||
170 | * |
||
171 | * @return string|bool |
||
172 | */ |
||
173 | private static function getOperatorMethod(string $operator) |
||
183 | |||
184 | /** |
||
185 | * Get operator method mapping. |
||
186 | * |
||
187 | * @return array |
||
188 | */ |
||
189 | private static function getOperators(): array |
||
216 | } |
||
217 |