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 AlterOperation extends Component |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * All database options |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | public static $DB_OPTIONS = array( |
||
34 | 'CHARACTER SET' => array(1, 'var'), |
||
35 | 'CHARSET' => array(1, 'var'), |
||
36 | 'DEFAULT CHARACTER SET' => array(1, 'var'), |
||
37 | 'DEFAULT CHARSET' => array(1, 'var'), |
||
38 | 'UPGRADE' => array(1, 'var'), |
||
39 | 'COLLATE' => array(2, 'var'), |
||
40 | 'DEFAULT COLLATE' => array(2, 'var'), |
||
41 | ); |
||
42 | |||
43 | /** |
||
44 | * All table options |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | public static $TABLE_OPTIONS = array( |
||
49 | 'ENGINE' => array(1, 'var='), |
||
50 | 'AUTO_INCREMENT' => array(1, 'var='), |
||
51 | 'AVG_ROW_LENGTH' => array(1, 'var'), |
||
52 | 'MAX_ROWS' => array(1, 'var'), |
||
53 | 'ROW_FORMAT' => array(1, 'var'), |
||
54 | 'ADD' => 1, |
||
55 | 'ALTER' => 1, |
||
56 | 'ANALYZE' => 1, |
||
57 | 'CHANGE' => 1, |
||
58 | 'CHECK' => 1, |
||
59 | 'COALESCE' => 1, |
||
60 | 'CONVERT' => 1, |
||
61 | 'DISABLE' => 1, |
||
62 | 'DISCARD' => 1, |
||
63 | 'DROP' => 1, |
||
64 | 'ENABLE' => 1, |
||
65 | 'IMPORT' => 1, |
||
66 | 'MODIFY' => 1, |
||
67 | 'OPTIMIZE' => 1, |
||
68 | 'ORDER' => 1, |
||
69 | 'PARTITION' => 1, |
||
70 | 'REBUILD' => 1, |
||
71 | 'REMOVE' => 1, |
||
72 | 'RENAME' => 1, |
||
73 | 'REORGANIZE' => 1, |
||
74 | 'REPAIR' => 1, |
||
75 | 'UPGRADE' => 1, |
||
76 | |||
77 | 'COLUMN' => 2, |
||
78 | 'CONSTRAINT' => 2, |
||
79 | 'DEFAULT' => 2, |
||
80 | 'TO' => 2, |
||
81 | 'BY' => 2, |
||
82 | 'FOREIGN' => 2, |
||
83 | 'FULLTEXT' => 2, |
||
84 | 'KEY' => 2, |
||
85 | 'KEYS' => 2, |
||
86 | 'PARTITIONING' => 2, |
||
87 | 'PRIMARY KEY' => 2, |
||
88 | 'SPATIAL' => 2, |
||
89 | 'TABLESPACE' => 2, |
||
90 | 'INDEX' => 2, |
||
91 | ); |
||
92 | |||
93 | /** |
||
94 | * All view options |
||
95 | * |
||
96 | * @var array |
||
97 | */ |
||
98 | public static $VIEW_OPTIONS = array( |
||
99 | 'AS' => 1, |
||
100 | ); |
||
101 | |||
102 | /** |
||
103 | * Options of this operation. |
||
104 | * |
||
105 | * @var OptionsArray |
||
106 | */ |
||
107 | public $options; |
||
108 | |||
109 | /** |
||
110 | * The altered field. |
||
111 | * |
||
112 | * @var Expression |
||
113 | */ |
||
114 | public $field; |
||
115 | |||
116 | /** |
||
117 | * Unparsed tokens. |
||
118 | * |
||
119 | * @var Token[]|string |
||
120 | */ |
||
121 | public $unknown = array(); |
||
122 | |||
123 | /** |
||
124 | * @param Parser $parser The parser that serves as context. |
||
125 | * @param TokensList $list The list of tokens that are being parsed. |
||
126 | * @param array $options Parameters for parsing. |
||
127 | * |
||
128 | * @return AlterOperation |
||
129 | */ |
||
130 | 5 | public static function parse(Parser $parser, TokensList $list, array $options = array()) |
|
237 | |||
238 | /** |
||
239 | * @param AlterOperation $component The component to be built. |
||
240 | * @param array $options Parameters for building. |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | 1 | public static function build($component, array $options = array()) |
|
253 | } |
||
254 |