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 | class RowsOfFields extends AbstractStructuredList implements ConversionInterface |
||
14 | { |
||
15 | /** |
||
16 | * @inheritdoc |
||
17 | */ |
||
18 | View Code Duplication | public function convert(FormatterOptions $options) |
|
27 | |||
28 | 4 | /** |
|
29 | 4 | * Restructure this data for output by converting it into a table |
|
30 | * transformation object. |
||
31 | * |
||
32 | 2 | * @param FormatterOptions $options Options that affect output formatting. |
|
33 | * @return Consolidation\OutputFormatters\Transformations\TableTransformation |
||
34 | 2 | */ |
|
35 | public function restructure(FormatterOptions $options) |
||
40 | |||
41 | 7 | public function getListData(FormatterOptions $options) |
|
45 | |||
46 | 7 | protected function defaultOptions() |
|
52 | } |
||
53 |
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.