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 declare(strict_types=1); |
||
29 | class FileMigrationRunner extends BaseMigrationRunner |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $migrationsPath; |
||
35 | |||
36 | /** |
||
37 | * @var string[] |
||
38 | */ |
||
39 | private $migrationClasses; |
||
40 | |||
41 | /** |
||
42 | 2 | * @param IoInterface $inOut |
|
43 | * @param string $migrationsPath |
||
44 | 2 | */ |
|
45 | public function __construct(IoInterface $inOut, string $migrationsPath) |
||
51 | |||
52 | 1 | /** |
|
53 | * @inheritdoc |
||
54 | */ |
||
55 | 1 | View Code Duplication | public function migrate(ContainerInterface $container): void |
73 | |||
74 | 1 | /** |
|
75 | * @inheritdoc |
||
76 | 1 | */ |
|
77 | protected function getMigrationClasses(): array |
||
81 | |||
82 | 1 | /** |
|
83 | * @return string |
||
84 | 1 | */ |
|
85 | protected function getMigrationsPath(): string |
||
89 | |||
90 | /** |
||
91 | * @param string $migrationsPath |
||
92 | 2 | * |
|
93 | * @return self |
||
94 | 2 | */ |
|
95 | protected function setMigrationsPath(string $migrationsPath): self |
||
101 | |||
102 | /** |
||
103 | * @param string[] $migrationClasses |
||
104 | 1 | * |
|
105 | * @return self |
||
106 | 1 | */ |
|
107 | private function setMigrationClasses(array $migrationClasses): self |
||
113 | } |
||
114 |
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.