Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
21 | class Condition extends Component |
||
22 | { |
||
23 | /** |
||
24 | * Logical operators that can be used to delimit expressions. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | public static $DELIMITERS = array('&&', '||', 'AND', 'OR', 'XOR'); |
||
29 | |||
30 | /** |
||
31 | * List of allowed reserved keywords in conditions. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | public static $ALLOWED_KEYWORDS = array( |
||
36 | 'ALL' => 1, |
||
37 | 'AND' => 1, |
||
38 | 'BETWEEN' => 1, |
||
39 | 'EXISTS' => 1, |
||
40 | 'IF' => 1, |
||
41 | 'IN' => 1, |
||
42 | 'INTERVAL' => 1, |
||
43 | 'IS' => 1, |
||
44 | 'LIKE' => 1, |
||
45 | 'MATCH' => 1, |
||
46 | 'NOT IN' => 1, |
||
47 | 'NOT NULL' => 1, |
||
48 | 'NOT' => 1, |
||
49 | 'NULL' => 1, |
||
50 | 'OR' => 1, |
||
51 | 'REGEXP' => 1, |
||
52 | 'RLIKE' => 1, |
||
53 | 'XOR' => 1, |
||
54 | ); |
||
55 | |||
56 | /** |
||
57 | * Identifiers recognized. |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | public $identifiers = array(); |
||
62 | |||
63 | /** |
||
64 | * Whether this component is an operator. |
||
65 | * |
||
66 | * @var bool |
||
67 | */ |
||
68 | public $isOperator = false; |
||
69 | |||
70 | /** |
||
71 | * The condition. |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | public $expr; |
||
76 | |||
77 | /** |
||
78 | * Constructor. |
||
79 | * |
||
80 | * @param string $expr the condition or the operator |
||
|
|||
81 | */ |
||
82 | 61 | public function __construct($expr = null) |
|
86 | |||
87 | /** |
||
88 | * @param Parser $parser the parser that serves as context |
||
89 | * @param TokensList $list the list of tokens that are being parsed |
||
90 | * @param array $options parameters for parsing |
||
91 | * |
||
92 | * @return Condition[] |
||
93 | */ |
||
94 | 60 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
212 | |||
213 | /** |
||
214 | * @param Condition[] $component the component to be built |
||
215 | * @param array $options parameters for building |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | 11 | public static function build($component, array $options = array()) |
|
227 | } |
||
228 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.