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 |
||
19 | class DashboardController extends Controller |
||
20 | { |
||
21 | /** |
||
22 | * Displays the current crontab and a form to add a new one. |
||
23 | * |
||
24 | * @AclAncestor("foa_cron_management_index") |
||
25 | * |
||
26 | * @return \Symfony\Component\HttpFoundation\Response |
||
27 | */ |
||
28 | public function indexAction() |
||
42 | |||
43 | /** |
||
44 | * Add a cron to the cron table |
||
45 | * |
||
46 | * @param Request $request |
||
47 | * |
||
48 | * @return RedirectResponse|Response |
||
49 | */ |
||
50 | public function addAction(Request $request) |
||
73 | |||
74 | /** |
||
75 | * Edit a cron |
||
76 | * |
||
77 | * @param $id - the line of the cron in the cron table |
||
78 | * |
||
79 | * @return RedirectResponse|Response |
||
80 | */ |
||
81 | public function editAction($id) |
||
105 | |||
106 | /** |
||
107 | * Wake up a cron from the cron table |
||
108 | * |
||
109 | * @param $id - the line of the cron in the cron table |
||
110 | * |
||
111 | * @return RedirectResponse |
||
112 | */ |
||
113 | public function wakeupAction($id) |
||
119 | |||
120 | /** |
||
121 | * Suspend a cron from the cron table |
||
122 | * |
||
123 | * @param $id - the line of the cron in the cron table |
||
124 | * |
||
125 | * @return RedirectResponse |
||
126 | */ |
||
127 | public function suspendAction($id) |
||
133 | |||
134 | /** |
||
135 | * Suspend a task from the cron table |
||
136 | * |
||
137 | * @param int $id - the line of the cron in the cron table |
||
138 | * @param bool $state |
||
139 | */ |
||
140 | protected function suspendTask($id, $state) |
||
154 | |||
155 | /** |
||
156 | * Remove a cron from the cron table |
||
157 | * |
||
158 | * @param $id - the line of the cron in the cron table |
||
159 | * |
||
160 | * @return RedirectResponse |
||
161 | */ |
||
162 | public function removeAction($id) |
||
173 | |||
174 | /** |
||
175 | * Gets a log file |
||
176 | * |
||
177 | * @param $id - the line of the cron in the cron table |
||
178 | * @param $type - the type of file, log or error |
||
179 | * |
||
180 | * @return Response |
||
181 | */ |
||
182 | public function fileAction($id, $type) |
||
200 | |||
201 | /** |
||
202 | * Adds a flash to the flash bag where flashes are array of messages |
||
203 | * |
||
204 | * @param $type |
||
205 | * @param $message |
||
206 | */ |
||
207 | protected function addFlash($type, $message) |
||
216 | } |
||
217 |
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.