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 |
||
25 | class Condition extends Component |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Logical operators that can be used to delimit expressions. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | public static $DELIMITERS = array('&&', '||', 'AND', 'OR', 'XOR'); |
||
34 | |||
35 | /** |
||
36 | * List of allowed reserved keywords in conditions. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | public static $ALLOWED_KEYWORDS = array( |
||
41 | 'ALL' => 1, |
||
42 | 'AND' => 1, |
||
43 | 'BETWEEN' => 1, |
||
44 | 'EXISTS' => 1, |
||
45 | 'IF' => 1, |
||
46 | 'IN' => 1, |
||
47 | 'INTERVAL' => 1, |
||
48 | 'IS' => 1, |
||
49 | 'LIKE' => 1, |
||
50 | 'MATCH' => 1, |
||
51 | 'NOT IN' => 1, |
||
52 | 'NOT NULL' => 1, |
||
53 | 'NOT' => 1, |
||
54 | 'NULL' => 1, |
||
55 | 'OR' => 1, |
||
56 | 'XOR' => 1, |
||
57 | ); |
||
58 | |||
59 | /** |
||
60 | * Identifiers recognized. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | public $identifiers = array(); |
||
65 | |||
66 | /** |
||
67 | * Whether this component is an operator. |
||
68 | * |
||
69 | * @var bool |
||
70 | */ |
||
71 | public $isOperator = false; |
||
72 | |||
73 | /** |
||
74 | * The condition. |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | public $expr; |
||
79 | |||
80 | /** |
||
81 | * Constructor. |
||
82 | * |
||
83 | * @param string $expr The condition or the operator. |
||
|
|||
84 | */ |
||
85 | 23 | public function __construct($expr = null) |
|
89 | |||
90 | /** |
||
91 | * @param Parser $parser The parser that serves as context. |
||
92 | * @param TokensList $list The list of tokens that are being parsed. |
||
93 | * @param array $options Parameters for parsing. |
||
94 | * |
||
95 | * @return Condition[] |
||
96 | */ |
||
97 | 22 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
215 | |||
216 | /** |
||
217 | * @param Condition[] $component The component to be built. |
||
218 | * @param array $options Parameters for building. |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | 4 | public static function build($component, array $options = array()) |
|
230 | } |
||
231 |
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.