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 SiteSettingController extends Controller |
||
19 | { |
||
20 | /** |
||
21 | * @Method("GET") |
||
22 | * @Route("", name="loevgaard_dandomain_altapay_site_setting_index") |
||
23 | * |
||
24 | * @param Request $request |
||
25 | * |
||
26 | * @return Response |
||
27 | */ |
||
28 | View Code Duplication | public function indexAction(Request $request) |
|
|
|||
29 | { |
||
30 | $repos = $this->get('loevgaard_dandomain_altapay.site_setting_repository'); |
||
31 | $siteSettings = $repos->findAllWithPaging($request->query->getInt('page', 1)); |
||
32 | |||
33 | return $this->render('@LoevgaardDandomainAltapay/site_setting/index.html.twig', [ |
||
34 | 'siteSettings' => $siteSettings, |
||
35 | ]); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @Method("GET") |
||
40 | * @Route("/{id}/show", name="loevgaard_dandomain_altapay_site_setting_show") |
||
41 | * |
||
42 | * @param SiteSetting $siteSetting |
||
43 | * |
||
44 | * @return Response |
||
45 | */ |
||
46 | public function showAction(SiteSetting $siteSetting) |
||
52 | |||
53 | /** |
||
54 | * @Method({"GET", "POST"}) |
||
55 | * @Route("/new", name="loevgaard_dandomain_altapay_site_setting_new") |
||
56 | * |
||
57 | * @param Request $request |
||
58 | * |
||
59 | * @return Response |
||
60 | */ |
||
61 | View Code Duplication | public function newAction(Request $request) |
|
72 | |||
73 | /** |
||
74 | * @Method({"GET", "POST"}) |
||
75 | * @Route("/{id}/edit", name="loevgaard_dandomain_altapay_site_setting_edit") |
||
76 | * |
||
77 | * @param SiteSetting $siteSetting |
||
78 | * @param Request $request |
||
79 | * |
||
80 | * @return Response |
||
81 | */ |
||
82 | View Code Duplication | public function editAction(SiteSetting $siteSetting, Request $request) |
|
92 | |||
93 | /** |
||
94 | * @param FormInterface $form |
||
95 | * @param SiteSetting $siteSetting |
||
96 | * @param Request $request |
||
97 | * |
||
98 | * @return null|RedirectResponse |
||
99 | */ |
||
100 | private function handleUpdate(FormInterface $form, SiteSetting $siteSetting, Request $request) |
||
120 | |||
121 | /** |
||
122 | * @param SiteSetting $siteSetting |
||
123 | * @param FormInterface $form |
||
124 | * |
||
125 | * @return Response |
||
126 | */ |
||
127 | private function updateResponse(SiteSetting $siteSetting, FormInterface $form): Response |
||
134 | |||
135 | /** |
||
136 | * @param SiteSetting $siteSetting |
||
137 | * |
||
138 | * @return FormInterface |
||
139 | */ |
||
140 | private function getForm(SiteSetting $siteSetting): FormInterface |
||
144 | } |
||
145 |
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.