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 |
||
16 | class SQLAnywhereSchemaManager extends AbstractSchemaManager |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | * |
||
21 | * Starts a database after creation |
||
22 | * as SQL Anywhere needs a database to be started |
||
23 | * before it can be used. |
||
24 | * |
||
25 | * @see startDatabase |
||
26 | */ |
||
27 | public function createDatabase(string $database) : void |
||
28 | { |
||
29 | parent::createDatabase($database); |
||
30 | $this->startDatabase($database); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | * |
||
36 | * Tries stopping a database before dropping |
||
37 | * as SQL Anywhere needs a database to be stopped |
||
38 | * before it can be dropped. |
||
39 | * |
||
40 | * @see stopDatabase |
||
41 | */ |
||
42 | public function dropDatabase(string $database) : void |
||
43 | { |
||
44 | $this->tryMethod('stopDatabase', $database); |
||
45 | parent::dropDatabase($database); |
||
46 | } |
||
47 | |||
48 | public function startDatabase(string $database) : void |
||
49 | { |
||
50 | assert($this->_platform instanceof SQLAnywherePlatform); |
||
51 | $this->_execSql($this->_platform->getStartDatabaseSQL($database)); |
||
52 | } |
||
53 | |||
54 | public function stopDatabase(string $database) : void |
||
55 | { |
||
56 | assert($this->_platform instanceof SQLAnywherePlatform); |
||
57 | $this->_execSql($this->_platform->getStopDatabaseSQL($database)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | protected function _getPortableDatabaseDefinition(array $database) : string |
||
64 | { |
||
65 | return $database['name']; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | protected function _getPortableSequenceDefinition(array $sequence) : Sequence |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | protected function _getPortableTableColumnDefinition(array $tableColumn) : Column |
||
80 | { |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | protected function _getPortableTableDefinition(array $table) : string |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | View Code Duplication | protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint |
|
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | protected function _getPortableViewDefinition(array $view) : View |
||
223 | } |
||
224 |
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.