1 | <?php |
||
17 | final class Operator |
||
18 | { |
||
19 | public const EQ = '='; |
||
20 | public const NEQ = '<>'; |
||
21 | public const GT = '>'; |
||
22 | public const GTE = '>='; |
||
23 | public const LT = '<'; |
||
24 | public const LTE = '<='; |
||
25 | |||
26 | // X IN (...) |
||
27 | public const IN = 'IN'; |
||
28 | public const NOT_IN = 'NOT IN'; |
||
29 | |||
30 | // LIKE |
||
31 | public const LIKE = 'LIKE'; |
||
32 | public const NOT_LIKE = 'NOT LIKE'; |
||
33 | |||
34 | // BETWEEN |
||
35 | public const BTW = 'BETWEEN'; |
||
36 | public const NOT_BTW = 'NOT BETWEEN'; |
||
37 | |||
38 | /** |
||
39 | * Mappings |
||
40 | * |
||
41 | * Transform the given format into normal operator format. |
||
42 | */ |
||
43 | private const OPERATOR_MAPPINGS = [ |
||
44 | '==' => self::EQ, |
||
45 | 'IS' => self::EQ, |
||
46 | '!=' => self::NEQ, |
||
47 | 'NOTIS' => self::NEQ, |
||
48 | '!IN' => self::NOT_IN, |
||
49 | '~' => self::LIKE, |
||
50 | '!LIKE' => self::NOT_LIKE, |
||
51 | '!~' => self::NOT_LIKE, |
||
52 | '..' => self::BTW, |
||
53 | '...' => self::BTW, |
||
54 | '!BETWEEN' => self::NOT_BTW, |
||
55 | '!..' => self::NOT_BTW, |
||
56 | '!...' => self::NOT_BTW, |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | private $operator; |
||
63 | |||
64 | /** |
||
65 | * Operator constructor. |
||
66 | * @param string $operator |
||
67 | */ |
||
68 | 43 | public function __construct(string $operator) |
|
72 | |||
73 | /** |
||
74 | * @param string $operator |
||
75 | * @return string |
||
76 | */ |
||
77 | 43 | private function normalize(string $operator): string |
|
85 | |||
86 | /** |
||
87 | * @param string $operator |
||
88 | * @return Operator |
||
89 | */ |
||
90 | public static function new(string $operator): self |
||
94 | |||
95 | /** |
||
96 | * @param string $operator |
||
97 | * @return Operator |
||
98 | */ |
||
99 | 4 | public function changeTo(string $operator): self |
|
105 | |||
106 | /** |
||
107 | * @return string |
||
108 | */ |
||
109 | 35 | public function toString(): string |
|
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | public function __toString(): string |
||
121 | |||
122 | /** |
||
123 | * @param string $operator |
||
124 | * @return bool |
||
125 | */ |
||
126 | 20 | public function is(string $operator): bool |
|
130 | } |
||
131 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.