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 ModerationSidebarContext extends DrupalSubContextBase { |
||
| 14 | |||
| 15 | use AwaitTrait; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Opens the moderation sidebar. |
||
| 19 | * |
||
| 20 | * @When I open the moderation sidebar |
||
| 21 | */ |
||
| 22 | View Code Duplication | public function openModerationSidebar() { |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Closes the moderation sidebar. |
||
| 41 | * |
||
| 42 | * @When I close the moderation sidebar |
||
| 43 | */ |
||
| 44 | View Code Duplication | public function closeModerationSidebar() { |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Selects a moderation sidebar item. |
||
| 63 | * |
||
| 64 | * @param string $item |
||
| 65 | * The moderation sidebar item to select. |
||
| 66 | * |
||
| 67 | * @Given I select the :item moderation sidebar button |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function selectModerationSidebarButton($item) { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Selects a moderation sidebar item. |
||
| 85 | * |
||
| 86 | * @param string $item |
||
| 87 | * The moderation sidebar item to select. |
||
| 88 | * |
||
| 89 | * @Given I select the :item moderation sidebar link |
||
| 90 | */ |
||
| 91 | View Code Duplication | public function selectModerationSidebarLink($item) { |
|
| 104 | |||
| 105 | } |
||
| 106 | |||
| 107 |
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.