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 |
||
16 | class SummaryFormContext implements Context |
||
17 | { |
||
18 | use CommonContextTrait; |
||
19 | |||
20 | private $elementMap = array( |
||
21 | 'name' => '#sf-nameForm', |
||
22 | 'location' => '#sf-locationForm', |
||
23 | 'employees' => '#sf-employeesManagement', |
||
24 | 'workflow' => '#sf-workflowSettings', |
||
25 | 'jobTitleAndLocation' => '#general-locationForm', |
||
26 | 'jobClassification' => '#sf-general-classifications', |
||
27 | 'customerNote' => '#sf-general-customerNote', |
||
28 | 'personalInformations' => '#sf-contact-contact', |
||
29 | 'resumePersonalInformations' => '#sf-contact', |
||
30 | ); |
||
31 | |||
32 | /** |
||
33 | * @When I click edit on :name form |
||
34 | * @TODO: [ZF3] move this method to CoreContext |
||
35 | */ |
||
36 | public function iClickEditOnForm($name) |
||
48 | |||
49 | /** |
||
50 | * @When I click :form form |
||
51 | */ |
||
52 | public function iClickForm($name) |
||
65 | |||
66 | /** |
||
67 | * @When I save :type form |
||
68 | */ |
||
69 | public function iSaveForm($type) |
||
82 | |||
83 | View Code Duplication | public function iSaveOrganizationName() |
|
90 | |||
91 | /** |
||
92 | * Saving organization workflow |
||
93 | */ |
||
94 | public function iSaveWorkflow() |
||
100 | |||
101 | View Code Duplication | public function iSaveOrganizationLocation() |
|
108 | |||
109 | |||
110 | View Code Duplication | public function iSaveJobClassification() |
|
117 | |||
118 | View Code Duplication | public function iSaveCustomerNote() |
|
125 | |||
126 | } |
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.