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 |
||
10 | View Code Duplication | class CategoryFeatureContext implements Context |
|
|
|||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var \ConsoleContext |
||
15 | */ |
||
16 | private $consoleContext; |
||
17 | |||
18 | /** @BeforeScenario */ |
||
19 | public function before(BeforeScenarioScope $scope) |
||
29 | |||
30 | /** |
||
31 | * @Given categories have been imported |
||
32 | */ |
||
33 | public function categoriesHaveBeenImported() |
||
38 | |||
39 | /** |
||
40 | * @Given files with categories to be updated are available |
||
41 | * @Given files with categories to be deleted are available |
||
42 | * @Given files with categories to be replaced are available |
||
43 | */ |
||
44 | public function filesWithCategoriesToBeUpdatedAreAvailable() |
||
51 | |||
52 | /** |
||
53 | * @Given the category import process has been started |
||
54 | */ |
||
55 | public function theCategoryImportProcessHasBeenStarted() |
||
60 | |||
61 | /** |
||
62 | * @Given the category deletion process has been started |
||
63 | */ |
||
64 | public function theCategoryDeletionProcessHasBeenStarted() |
||
69 | |||
70 | /** |
||
71 | * @Given the category replacement process has been started |
||
72 | */ |
||
73 | public function theCategoryReplacementProcessHasBeenStarted() |
||
78 | } |
||
79 |
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.