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 |
||
11 | abstract class AbstractDialect implements DialectInterface |
||
12 | { |
||
13 | use BuilderTrait; |
||
14 | |||
15 | /** |
||
16 | * @var SyntaxFormatterInterface |
||
17 | */ |
||
18 | protected $formatter; |
||
19 | |||
20 | /** |
||
21 | * MysqlDialect constructor. |
||
22 | * |
||
23 | * @param SyntaxFormatterInterface|null $formatter |
||
24 | */ |
||
25 | public function __construct(SyntaxFormatterInterface $formatter = null) |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | abstract public function getIdentifierQuote(); |
||
34 | |||
35 | /** |
||
36 | * @param string $syntax |
||
37 | * @param array $params |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | protected function format($syntax, array $params = []) |
||
50 | |||
51 | /** |
||
52 | * @param TableNodeInterface $table |
||
53 | * @param string $column |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | View Code Duplication | public function getDropColumn(TableNodeInterface $table, $column) |
|
67 | |||
68 | /** |
||
69 | * @param TableNodeInterface $table |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public function getDoesTableExist(TableNodeInterface $table) |
||
89 | |||
90 | /** |
||
91 | * @param TableNodeInterface $table |
||
92 | * @param string|null $where |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | View Code Duplication | public function getDeleteFromTable(TableNodeInterface $table, $where = null) |
|
110 | |||
111 | /** |
||
112 | * @param TableNodeInterface $from |
||
113 | * @param TableNodeInterface $to |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | public function getCopyTable(TableNodeInterface $from, TableNodeInterface $to) |
||
152 | |||
153 | /** |
||
154 | * @param TableNodeInterface $table |
||
155 | * |
||
156 | * @return array [sql, params] |
||
157 | */ |
||
158 | public function getSelectSyntax(TableNodeInterface $table) |
||
185 | |||
186 | /** |
||
187 | * @param TableNodeInterface $table |
||
188 | * @param string[] $rows |
||
189 | * |
||
190 | * @return array [sql, params] |
||
191 | */ |
||
192 | public function getInsertSyntax(TableNodeInterface $table, array $rows) |
||
222 | } |
||
223 |
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.