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 AttributeSetFeatureContext 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 attribute sets have been imported |
||
32 | */ |
||
33 | public function attributeSetsHaveBeenImported() |
||
38 | |||
39 | /** |
||
40 | * @Given files with attribute sets to be updated are available |
||
41 | * @Given files with attribute sets to be deleted are available |
||
42 | * @Given files with attribute sets to be replaced are available |
||
43 | */ |
||
44 | public function filesWithAttributeSetsToBeUpdatedAreAvailable() |
||
51 | |||
52 | /** |
||
53 | * @Given the attribute set import process has been started |
||
54 | */ |
||
55 | public function theAttributeSetImportProcessHasBeenStarted() |
||
60 | |||
61 | /** |
||
62 | * @Given the attribute set deletion process has been started |
||
63 | */ |
||
64 | public function theAttributeSetDeletionProcessHasBeenStarted() |
||
69 | |||
70 | /** |
||
71 | * @Given the attribute set replacement process has been started |
||
72 | */ |
||
73 | public function theAttributeSetReplacementProcessHasBeenStarted() |
||
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.