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 | View Code Duplication | abstract class AbstractCategoryMessage implements MessageInterface |
|
|
|
|||
| 14 | { |
||
| 15 | use SiteAwareMessageTrait; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var int|null |
||
| 19 | */ |
||
| 20 | private $parentRootId; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var bool|null |
||
| 24 | */ |
||
| 25 | private $enabled; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var CategoryTranslationMessage[] |
||
| 29 | */ |
||
| 30 | private $translations = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return int|null |
||
| 34 | */ |
||
| 35 | public function getParentRootId() |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param int|null $parentRootId |
||
| 42 | */ |
||
| 43 | public function setParentRootId(int $parentRootId = null) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return bool|null |
||
| 50 | */ |
||
| 51 | public function isEnabled() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param bool|null $enabled |
||
| 58 | */ |
||
| 59 | public function setEnabled(bool $enabled = null) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return CategoryTranslationMessage[] |
||
| 66 | */ |
||
| 67 | public function getTranslations(): array |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param CategoryTranslationMessage $translation |
||
| 74 | */ |
||
| 75 | public function addTranslation(CategoryTranslationMessage $translation) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param CategoryTranslationMessage $translation |
||
| 82 | */ |
||
| 83 | public function removeTranslation(CategoryTranslationMessage $translation) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | public function build() |
||
| 99 | } |
||
| 100 |
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.