1 | <?php |
||
15 | class CompareHelper |
||
16 | { |
||
17 | // Dont change order - longer will be first (before other started from same symbols) |
||
18 | // @2DO: when updated StrHepler::findPrefix - refactor for remove aliases |
||
19 | const RULES = [ |
||
20 | '<=', '=<', '>=', '=>','!=','<>', '!like:','!contain:', '!in:', 'like:','contain:', 'in:', '<', '>', '!', '=' |
||
21 | ]; |
||
22 | const STARED_RULES = [ |
||
23 | '*<=', '*=<', '*>=', '*=>','*!=','*<>', '*!like:','*!contain:', '*!in:', '*like:','*contain:', '*in:', '*<', '*>', '*!', '*=' |
||
24 | ]; |
||
25 | const RULES_ALIASES = [ |
||
26 | '=<' => '<=', |
||
27 | '=>' => '>=', |
||
28 | '!' => '!=', |
||
29 | '<>' => '!=', |
||
30 | |||
31 | '*=<' => '*<=', |
||
32 | '*=>' => '*>=', |
||
33 | '*!' => '*!=', |
||
34 | '*<>' => '*!=', |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * Compare two values using orders list in format [field1, field2, !field3] |
||
39 | * where ! is reverse ordering |
||
40 | * @param array $orders |
||
41 | * @param type $value1 |
||
42 | * @param type $value2 |
||
43 | * @return int |
||
44 | */ |
||
45 | public static function compareByOrders(array $orders, $value1, $value2) : int |
||
63 | |||
64 | /** |
||
65 | * Find prefix supported by ruleCheck |
||
66 | * return two value. first is rule, second is last part of string |
||
67 | * |
||
68 | * @param string $str |
||
69 | * @return array |
||
70 | */ |
||
71 | public static function findRulePrefix(string $str) : array |
||
77 | |||
78 | /** |
||
79 | * If array of rules is in "simple format" |
||
80 | * convert it to full format |
||
81 | * @param array $rules |
||
82 | * @return array |
||
83 | */ |
||
84 | public static function tryPrepareSimpleRules(array $rules) : array |
||
96 | |||
97 | /** |
||
98 | * Do simple checks by rules |
||
99 | * rule is one of: '<=', '=<', '>=', '=>', '!like:','!contain:', '!in:', |
||
100 | * 'like:','contain:', 'in:', '<', '>', '!', '=' |
||
101 | * value1 and value2 is is parameters for compare |
||
102 | * |
||
103 | * @param string $rule |
||
104 | * @param mixed $value1 |
||
105 | * @param mixed $value2 |
||
106 | * @return bool |
||
107 | * @throws \Exception |
||
108 | */ |
||
109 | public static function checkRule(string $rule, $value1, $value2) : bool |
||
140 | |||
141 | protected static function tryRuleAliase(string $rule) : string |
||
149 | } |
||
150 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.