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 |
||
16 | class TableExporter implements TableExporterInterface, BuilderAwareInterface, LoggerAwareInterface |
||
17 | { |
||
18 | use OptionalLoggerTrait; |
||
19 | use BuilderTrait; |
||
20 | |||
21 | /** @var FileNodeInterface */ |
||
22 | private $file; |
||
23 | /** @var FormatInterface */ |
||
24 | private $format; |
||
25 | |||
26 | /** |
||
27 | * TableExporter constructor. |
||
28 | * |
||
29 | * @param FileNodeInterface $file |
||
30 | * @param FormatInterface $format |
||
31 | */ |
||
32 | public function __construct(FileNodeInterface $file, FormatInterface $format) |
||
37 | |||
38 | /** |
||
39 | * Export a table to something |
||
40 | * |
||
41 | * @param TableNodeInterface $table |
||
42 | * |
||
43 | * @return FileNodeInterface |
||
44 | */ |
||
45 | View Code Duplication | public function export(TableNodeInterface $table) |
|
59 | } |
||
60 |
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.