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 |
||
7 | class MysqlDialect extends AbstractDialect |
||
8 | { |
||
9 | /** |
||
10 | * @return string |
||
11 | */ |
||
12 | public function getIdentifierQuote() |
||
16 | |||
17 | /** |
||
18 | * @param TableNodeInterface $old |
||
19 | * @param TableNodeInterface $new |
||
20 | * |
||
21 | * @return array |
||
22 | */ |
||
23 | View Code Duplication | public function getCreateTableLike(TableNodeInterface $old, TableNodeInterface $new) |
|
33 | |||
34 | /** |
||
35 | * @param TableNodeInterface $source |
||
36 | * @param TableNodeInterface $join |
||
37 | * @param string $on |
||
38 | * @param string|null $where |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | public function getDeleteTableJoinSoftDelete( |
||
72 | |||
73 | /** |
||
74 | * @param TableNodeInterface $source |
||
75 | * @param TableNodeInterface $join |
||
76 | * @param string $on |
||
77 | * @param string|null $where |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | View Code Duplication | public function getDeleteTableJoin( |
|
104 | |||
105 | /** |
||
106 | * @param TableNodeInterface $table |
||
107 | * @param string|null $where |
||
108 | * |
||
109 | * @return array [sql, bind] |
||
110 | */ |
||
111 | public function getDeleteFromTableSoftDelete(TableNodeInterface $table, $where = null) |
||
130 | |||
131 | /** |
||
132 | * @param TableNodeInterface $table |
||
133 | * @param array $columns |
||
134 | * @param array $primary |
||
135 | * @param array $index |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getCreateTable(TableNodeInterface $table, array $columns, array $primary, array $index) |
||
154 | |||
155 | /** |
||
156 | * @param array $column |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | View Code Duplication | public function getColumnDefinition(array $column) |
|
167 | |||
168 | /** |
||
169 | * @param array $key |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getPrimaryKeyDefinition(array $key) |
||
177 | |||
178 | /** |
||
179 | * @param array $index |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getIndexDefinition(array $index) |
||
187 | |||
188 | /** |
||
189 | * @param TableNodeInterface $table |
||
190 | * |
||
191 | * @return array [sql, bind] |
||
192 | */ |
||
193 | public function getDescribeTable(TableNodeInterface $table) |
||
197 | |||
198 | /** |
||
199 | * @param TableNodeInterface $table |
||
200 | * |
||
201 | * @return array [sql, bind] |
||
202 | */ |
||
203 | public function getCreateSyntax(TableNodeInterface $table) |
||
210 | } |
||
211 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.