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 |
||
32 | class IssueController extends Controller |
||
33 | { |
||
34 | /** |
||
35 | * Project issue index page (List project issues) |
||
36 | * |
||
37 | * @param Project $project |
||
38 | * @param Issue $issue |
||
39 | * @param CommentForm $form |
||
40 | * |
||
41 | * @return \Illuminate\View\View |
||
42 | */ |
||
43 | 18 | public function getIndex(Project $project, Issue $issue, CommentForm $form) |
|
69 | |||
70 | /** |
||
71 | * Ajax: Assign new user to an issue |
||
72 | * |
||
73 | * @param Issue $issue |
||
74 | * @param Request $request |
||
75 | * |
||
76 | * @return \Symfony\Component\HttpFoundation\Response |
||
77 | */ |
||
78 | 1 | View Code Duplication | public function postAssign(Issue $issue, Request $request) |
87 | |||
88 | /** |
||
89 | * Ajax: save comment |
||
90 | * |
||
91 | * @param Comment $comment |
||
92 | * @param Request $request |
||
93 | * |
||
94 | * @return \Symfony\Component\HttpFoundation\Response |
||
95 | */ |
||
96 | 1 | public function postEditComment(Comment $comment, Request $request) |
|
106 | |||
107 | /** |
||
108 | * To add new comment to an issue |
||
109 | * |
||
110 | * @param Project $project |
||
111 | * @param Issue $issue |
||
112 | * @param Comment $comment |
||
113 | * @param FormRequest\Comment $request |
||
114 | * |
||
115 | * @return \Illuminate\Http\RedirectResponse |
||
116 | */ |
||
117 | 4 | public function getAddComment(Project $project, Issue $issue, Comment $comment, FormRequest\Comment $request) |
|
127 | |||
128 | /** |
||
129 | * Ajax: to delete a comment |
||
130 | * |
||
131 | * @param Comment $comment |
||
132 | * |
||
133 | * @return \Symfony\Component\HttpFoundation\Response |
||
134 | */ |
||
135 | 1 | public function getDeleteComment(Comment $comment) |
|
141 | |||
142 | /** |
||
143 | * New issue form |
||
144 | * |
||
145 | * @param Project $project |
||
146 | * @param IssueForm $form |
||
147 | * |
||
148 | * @return \Illuminate\View\View |
||
149 | */ |
||
150 | 5 | public function getNew(Project $project, IssueForm $form) |
|
158 | |||
159 | /** |
||
160 | * To create a new issue |
||
161 | * |
||
162 | * @param Project $project |
||
163 | * @param Issue $issue |
||
164 | * @param FormRequest\Issue $request |
||
165 | * |
||
166 | * @return \Illuminate\Http\RedirectResponse |
||
167 | */ |
||
168 | 2 | View Code Duplication | public function postNew(Project $project, Issue $issue, FormRequest\Issue $request) |
177 | |||
178 | /** |
||
179 | * Edit an existing issue form |
||
180 | * |
||
181 | * @param Project $project |
||
182 | * @param Issue $issue |
||
183 | * @param IssueForm $form |
||
184 | * |
||
185 | * @return \Illuminate\View\View |
||
186 | */ |
||
187 | 2 | public function getEdit(Project $project, Issue $issue, IssueForm $form) |
|
202 | |||
203 | /** |
||
204 | * To update an existing issue details |
||
205 | * |
||
206 | * @param Project $project |
||
207 | * @param Issue $issue |
||
208 | * @param FormRequest\Issue $request |
||
209 | * |
||
210 | * @return \Illuminate\Http\RedirectResponse |
||
211 | */ |
||
212 | 1 | View Code Duplication | public function postEdit(Project $project, Issue $issue, FormRequest\Issue $request) |
221 | |||
222 | /** |
||
223 | * To close or reopen an issue |
||
224 | * |
||
225 | * @param Project $project |
||
226 | * @param Issue $issue |
||
227 | * @param int $status |
||
228 | * |
||
229 | * @return \Illuminate\Http\RedirectResponse |
||
230 | */ |
||
231 | 2 | public function getClose(Project $project, Issue $issue, $status = 0) |
|
245 | |||
246 | /** |
||
247 | * To upload an attachment file |
||
248 | * |
||
249 | * @param Project $project |
||
250 | * @param Attachment $attachment |
||
251 | * @param Request $request |
||
252 | * |
||
253 | * @return \Symfony\Component\HttpFoundation\Response |
||
254 | */ |
||
255 | 3 | public function postUploadAttachment(Project $project, Attachment $attachment, Request $request) |
|
286 | |||
287 | /** |
||
288 | * Ajax: to remove an attachment file |
||
289 | * |
||
290 | * @param Project $project |
||
291 | * @param Attachment $attachment |
||
292 | * @param Request $request |
||
293 | * |
||
294 | * @return \Symfony\Component\HttpFoundation\Response |
||
295 | */ |
||
296 | 1 | public function postRemoveAttachment(Project $project, Attachment $attachment, Request $request) |
|
302 | |||
303 | /** |
||
304 | * Display an attachment file such as image |
||
305 | * |
||
306 | * @param Project $project |
||
307 | * @param Issue $issue |
||
308 | * @param Attachment $attachment |
||
309 | * @param Request $request |
||
310 | * |
||
311 | * @return Response |
||
312 | */ |
||
313 | 2 | public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request) |
|
346 | |||
347 | /** |
||
348 | * Download an attachment file |
||
349 | * |
||
350 | * @param Project $project |
||
351 | * @param Issue $issue |
||
352 | * @param Attachment $attachment |
||
353 | * |
||
354 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||
355 | */ |
||
356 | 1 | public function getDownloadAttachment(Project $project, Issue $issue, Attachment $attachment) |
|
365 | |||
366 | /** |
||
367 | * Ajax: move an issue to another project |
||
368 | * |
||
369 | * @param Issue $issue |
||
370 | * @param Request $request |
||
371 | * |
||
372 | * @return \Symfony\Component\HttpFoundation\Response |
||
373 | */ |
||
374 | 1 | public function postChangeProject(Issue $issue, Request $request) |
|
380 | |||
381 | /** |
||
382 | * Ajax: change status of an issue |
||
383 | * |
||
384 | * @param Issue $issue |
||
385 | * @param Request $request |
||
386 | * |
||
387 | * @return \Symfony\Component\HttpFoundation\Response |
||
388 | */ |
||
389 | public function postChangeStatusTag(Issue $issue, Request $request) |
||
397 | } |
||
398 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.