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 ListController extends Controller |
||
25 | { |
||
26 | /** |
||
27 | * Main controller action. |
||
28 | * |
||
29 | * @param Request $request |
||
30 | * |
||
31 | * @return \Symfony\Component\HttpFoundation\Response |
||
32 | */ |
||
33 | 5 | View Code Duplication | public function indexAction(Request $request) |
46 | |||
47 | /** |
||
48 | * Get rates for list view. Process filters if submitted. |
||
49 | * |
||
50 | * @param Form $filterForm |
||
51 | * |
||
52 | * @return \RunOpenCode\ExchangeRate\Contract\RateInterface[] |
||
53 | */ |
||
54 | 4 | protected function getRates(Form $filterForm) |
|
67 | |||
68 | /** |
||
69 | * Get filter form |
||
70 | * |
||
71 | * @param Request $request |
||
72 | * |
||
73 | * @return Form |
||
74 | */ |
||
75 | 4 | protected function getFilterForm(Request $request) |
|
83 | |||
84 | /** |
||
85 | * Get FQCN of FilterType form. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 4 | protected function getFilterFormType() |
|
93 | |||
94 | /** |
||
95 | * Get Twig template path. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 4 | protected function getTwigTemplate() |
|
103 | } |
||
104 |
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.