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 |
||
13 | View Code Duplication | final class Migration20200915025000 extends AbstractMigration |
|
|
|||
14 | { |
||
15 | use ModelFactoryTrait; |
||
16 | |||
17 | /** |
||
18 | * Short description of what the patch will do. |
||
19 | * |
||
20 | * @return string |
||
21 | */ |
||
22 | public function description(): string |
||
26 | |||
27 | /** |
||
28 | * Inject dependencies from a DI Container. |
||
29 | * |
||
30 | * @param Container $container A Pimple DI service container. |
||
31 | * @return void |
||
32 | */ |
||
33 | protected function setDependencies(Container $container): void |
||
39 | |||
40 | /** |
||
41 | * Apply migration |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | public function up(): void |
||
64 | } |
||
65 |
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.