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 |
||
18 | class CountryMappingController extends Controller |
||
19 | { |
||
20 | /** |
||
21 | * @Method("GET") |
||
22 | * @Route("", name="loevgaard_pakkelabels_country_mapping_index") |
||
23 | * |
||
24 | * @param Request $request |
||
25 | * |
||
26 | * @return Response |
||
27 | */ |
||
28 | public function indexAction(Request $request) |
||
40 | |||
41 | /** |
||
42 | * @Method("GET") |
||
43 | * @Route("/{id}/show", name="loevgaard_pakkelabels_country_mapping_show") |
||
44 | * |
||
45 | * @param CountryMapping $countryMapping |
||
46 | * |
||
47 | * @return Response |
||
48 | */ |
||
49 | public function showAction(CountryMapping $countryMapping) |
||
55 | |||
56 | /** |
||
57 | * @Method({"GET", "POST"}) |
||
58 | * @Route("/new", name="loevgaard_pakkelabels_country_mapping_new") |
||
59 | * |
||
60 | * @param Request $request |
||
61 | * |
||
62 | * @return Response |
||
63 | */ |
||
64 | View Code Duplication | public function newAction(Request $request) |
|
75 | |||
76 | /** |
||
77 | * @Method({"GET", "POST"}) |
||
78 | * @Route("/{id}/edit", name="loevgaard_pakkelabels_country_mapping_edit") |
||
79 | * |
||
80 | * @param CountryMapping $countryMapping |
||
81 | * @param Request $request |
||
82 | * |
||
83 | * @return Response |
||
84 | */ |
||
85 | View Code Duplication | public function editAction(CountryMapping $countryMapping, Request $request) |
|
95 | |||
96 | /** |
||
97 | * @param Form $form |
||
98 | * @param CountryMapping $countryMapping |
||
99 | * @param Request $request |
||
100 | * @return null|RedirectResponse |
||
101 | */ |
||
102 | private function handleUpdate(Form $form, CountryMapping $countryMapping, Request $request) |
||
129 | |||
130 | /** |
||
131 | * @param CountryMapping $countryMapping |
||
132 | * @param Form $form |
||
133 | * @return Response |
||
134 | */ |
||
135 | private function updateResponse(CountryMapping $countryMapping, Form $form) : Response |
||
142 | |||
143 | /** |
||
144 | * @param CountryMapping $countryMapping |
||
145 | * @return Form |
||
146 | */ |
||
147 | private function getForm(CountryMapping $countryMapping) : Form |
||
151 | |||
152 | } |
||
153 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.