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 |
||
17 | class RedshiftTableExporter implements TableExporterInterface, BuilderAwareInterface, LoggerAwareInterface |
||
18 | { |
||
19 | use OptionalLoggerTrait; |
||
20 | use BuilderTrait; |
||
21 | |||
22 | /** @var FileNodeInterface */ |
||
23 | private $file; |
||
24 | |||
25 | /** |
||
26 | * MysqlTableExporter constructor. |
||
27 | * |
||
28 | * @param FileNodeInterface $file |
||
29 | */ |
||
30 | public function __construct(FileNodeInterface $file) |
||
38 | |||
39 | /** |
||
40 | * @param FileNodeInterface $file |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | private function validateFile(FileNodeInterface $file) |
||
49 | |||
50 | /** |
||
51 | * @param TableNodeInterface $table |
||
52 | * |
||
53 | * @return FileNodeInterface |
||
54 | */ |
||
55 | View Code Duplication | public function export(TableNodeInterface $table) |
|
69 | } |
||
70 |
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.