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 |
||
15 | class Version030702Date20200626072306 extends SimpleMigrationStep { |
||
16 | |||
17 | /** |
||
18 | * @param IOutput $output |
||
19 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
20 | * @param array $options |
||
21 | */ |
||
22 | public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
||
24 | |||
25 | /** |
||
26 | * @param IOutput $output |
||
27 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
28 | * @param array $options |
||
29 | * @return null|ISchemaWrapper |
||
30 | */ |
||
31 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
||
89 | |||
90 | /** |
||
91 | * @param IOutput $output |
||
92 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
93 | * @param array $options |
||
94 | */ |
||
95 | public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
||
97 | } |
||
98 |
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.