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 |
||
7 | class WebsiteDataConverter extends IntegrationAwareDataConverter |
||
8 | { |
||
9 | const NAME_MAX_LENGTH = 255; |
||
10 | const CODE_MAX_LENGTH = 32; |
||
11 | const ELLIPSIS = '...'; |
||
12 | |||
13 | /** |
||
14 | * {@inheritdoc} |
||
15 | */ |
||
16 | protected function getHeaderConversionRules() |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | protected function getBackendHeader() |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function convertToImportFormat(array $importedRecord, $skipNullValues = true) |
||
52 | |||
53 | /** |
||
54 | * Cuts field value to max length and add ellipsis |
||
55 | * |
||
56 | * @param string $fieldValue |
||
57 | * @param int $maxLength |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | private function cutFieldToLength($fieldValue, $maxLength) |
||
71 | } |
||
72 |
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.