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); |
||
37 | class DataCommand implements CommandInterface |
||
38 | { |
||
39 | /** |
||
40 | * Command name. |
||
41 | */ |
||
42 | const NAME = 'l:db'; |
||
43 | |||
44 | /** Argument name */ |
||
45 | const ARG_ACTION = 'action'; |
||
46 | |||
47 | /** Command action */ |
||
48 | const ACTION_MIGRATE = 'migrate'; |
||
49 | |||
50 | /** Command action */ |
||
51 | const ACTION_SEED = 'seed'; |
||
52 | |||
53 | /** Command action */ |
||
54 | const ACTION_ROLLBACK = 'rollback'; |
||
55 | |||
56 | /** Option name */ |
||
57 | const OPT_PATH = 'path'; |
||
58 | |||
59 | /** |
||
60 | 1 | * @inheritdoc |
|
61 | */ |
||
62 | 1 | public static function getName(): string |
|
66 | |||
67 | /** |
||
68 | 1 | * @inheritdoc |
|
69 | */ |
||
70 | 1 | public static function getDescription(): string |
|
74 | |||
75 | /** |
||
76 | 1 | * @inheritdoc |
|
77 | */ |
||
78 | 1 | public static function getHelp(): string |
|
82 | |||
83 | /** |
||
84 | 1 | * @inheritdoc |
|
85 | */ |
||
86 | 1 | public static function getArguments(): array |
|
100 | |||
101 | /** |
||
102 | 1 | * @inheritdoc |
|
103 | */ |
||
104 | public static function getOptions(): array |
||
116 | |||
117 | /** |
||
118 | 1 | * @inheritdoc |
|
119 | */ |
||
120 | 1 | public static function execute(ContainerInterface $container, IoInterface $inOut): void |
|
124 | |||
125 | /** |
||
126 | * @param ContainerInterface $container |
||
127 | * @param IoInterface $inOut |
||
128 | * |
||
129 | * @return void |
||
130 | * |
||
131 | * @throws ContainerExceptionInterface |
||
132 | * @throws NotFoundExceptionInterface |
||
133 | * @throws InvalidArgumentException |
||
134 | 4 | * @throws DBALException |
|
135 | */ |
||
136 | 4 | protected function run(ContainerInterface $container, IoInterface $inOut): void |
|
166 | |||
167 | /** |
||
168 | * @param IoInterface $inOut |
||
169 | * @param string $path |
||
170 | * |
||
171 | 1 | * @return FileMigrationRunner |
|
172 | */ |
||
173 | 1 | protected function createMigrationRunner(IoInterface $inOut, string $path): FileMigrationRunner |
|
177 | |||
178 | /** |
||
179 | * @param IoInterface $inOut |
||
180 | * @param string $seedsPath |
||
181 | * @param callable|null $seedInit |
||
182 | * @param string $seedsTable |
||
183 | * |
||
184 | 1 | * @return FileSeedRunner |
|
185 | */ |
||
186 | protected function createSeedRunner( |
||
194 | } |
||
195 |
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.