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 FeatureContext extends OroFeatureContext implements OroElementFactoryAware |
||
11 | { |
||
12 | use ElementFactoryDictionary; |
||
13 | |||
14 | /** |
||
15 | * @When /^(?:|I )select (?P<title>([\w\s]+)) as email attachment from record$/ |
||
16 | */ |
||
17 | public function selectEmailAttachment($title) |
||
27 | |||
28 | /** |
||
29 | * @Then /^(?P<contactsCount>(?:|one|two|\d+)) contacts added to form$/ |
||
30 | */ |
||
31 | public function assertCountContactsAddedToForm($contactsCount) |
||
35 | |||
36 | /** |
||
37 | * @When /^(?:|I should )see (?P<contactsCount>(?:|one|two|\d+)) contact(?:|s)$/ |
||
38 | */ |
||
39 | public function assertCountOfContacts($contactsCount) |
||
46 | |||
47 | /** |
||
48 | * @When :name should be default contact |
||
49 | */ |
||
50 | View Code Duplication | public function assertDefaultContact($name) |
|
64 | |||
65 | |||
66 | /** |
||
67 | * @Then /^(?:|I )select ([\w\s]*) contact as default$/ |
||
68 | */ |
||
69 | View Code Duplication | public function selectContactAsDefault($name) |
|
81 | |||
82 | /** |
||
83 | * @Then delete :name contact |
||
84 | */ |
||
85 | View Code Duplication | public function deleteContact($name) |
|
97 | |||
98 | /** |
||
99 | * @return NodeElement[] |
||
100 | */ |
||
101 | protected function getFormContacts() |
||
107 | |||
108 | /** |
||
109 | * @param int|string $count |
||
110 | * @return int |
||
111 | */ |
||
112 | View Code Duplication | protected function getCount($count) |
|
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.