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 | class ProductFeatureContext implements Context |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var \ConsoleContext |
||
15 | */ |
||
16 | private $consoleContext; |
||
17 | |||
18 | /** |
||
19 | * @var \FeatureContext |
||
20 | */ |
||
21 | private $featureContext; |
||
22 | |||
23 | /** @BeforeScenario */ |
||
24 | public function before(BeforeScenarioScope $scope) |
||
35 | |||
36 | /** |
||
37 | * @Then title and price are :arg1,( ) |
||
38 | * @Then title and price are :arg1, :arg2 |
||
39 | */ |
||
40 | public function assertTitleAndPrice($arg1, $arg2 = null) |
||
53 | |||
54 | /** |
||
55 | * @Given files with products to be updated are available |
||
56 | * @Given files with products to be deleted are available |
||
57 | */ |
||
58 | View Code Duplication | public function filesWithProductsToBeUpdatedAreAvailable() |
|
67 | |||
68 | /** |
||
69 | * @Given files with products to be replaced are available |
||
70 | */ |
||
71 | View Code Duplication | public function filesWithProductsToBeReplacedAreAvailable() |
|
80 | |||
81 | /** |
||
82 | * @Given the product import process has been started |
||
83 | */ |
||
84 | public function theProductImportProcessHasBeenStarted() |
||
89 | |||
90 | /** |
||
91 | * @Given the product deletion process has been started |
||
92 | */ |
||
93 | public function theProductDeletionProcessHasBeenStarted() |
||
98 | |||
99 | /** |
||
100 | * @Given the product replacement process has been started |
||
101 | */ |
||
102 | public function theProductReplacementProcessHasBeenStarted() |
||
107 | } |
||
108 |
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.