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 |
||
24 | class MultiTermChoice extends SingleTermChoice |
||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | View Code Duplication | public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
|
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function getState(Request $request) |
||
50 | |||
51 | /** |
||
52 | * Returns url with selected term applied. |
||
53 | * |
||
54 | * @param string $key |
||
55 | * @param ViewData $data |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | protected function getOptionUrlParameters($key, ViewData $data) |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | protected function getUnsetUrlParameters($key, ViewData $data) |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | protected function isChoiceActive($key, ViewData $data) |
||
97 | } |
||
98 |
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.