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 AttributeFeatureContext 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 attributes have been imported |
||
32 | */ |
||
33 | public function attributesHaveBeenImported() |
||
38 | |||
39 | /** |
||
40 | * @Given files with attributes to be updated are available |
||
41 | * @Given files with attributes to be replaced are available |
||
42 | * @Given files with attributes to be deleted are available |
||
43 | */ |
||
44 | public function filesWithAttributesToBeUpdatedAreAvailable() |
||
51 | |||
52 | /** |
||
53 | * @Given the attribute(s) import process has been started |
||
54 | */ |
||
55 | public function theAttributeImportProcessHasBeenStarted() |
||
60 | |||
61 | /** |
||
62 | * @Given the attribute(s) deletion process has been started |
||
63 | */ |
||
64 | public function theAttributeDeletionProcessHasBeenStarted() |
||
69 | |||
70 | /** |
||
71 | * @Given the attribute(s) replacement process has been started |
||
72 | */ |
||
73 | public function theAttributeReplacementProcessHasBeenStarted() |
||
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.