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 |
||
| 13 | class ResourceController extends BaseController |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Gets a document from the courses/MATHS/document/file.jpg to the user |
||
| 17 | * @todo check permissions |
||
| 18 | * @param string $course |
||
| 19 | * @param string $file |
||
| 20 | * @return \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
| 21 | */ |
||
| 22 | public function getDocumentAction($course, $file) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Gets a document from the data/courses/MATHS/document/file.jpg to the user |
||
| 45 | * @todo check permissions |
||
| 46 | * @param Application $app |
||
| 47 | * @param string $courseCode |
||
| 48 | * @param string $file |
||
| 49 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void |
||
| 50 | */ |
||
| 51 | public function getCourseUploadFileAction( |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Gets a document from the data/courses/MATHS/scorm/file.jpg to the user |
||
| 70 | * @todo check permissions |
||
| 71 | * @param Application $app |
||
| 72 | * @param string $courseCode |
||
| 73 | * @param string $file |
||
| 74 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void |
||
| 75 | */ |
||
| 76 | public function getScormDocumentAction(Application $app, $courseCode, $file) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Gets a document from the data/default_platform_document/* folder |
||
| 92 | * @param Application $app |
||
| 93 | * @param string $file |
||
| 94 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function getDefaultCourseDocumentAction(Application $app, $file) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @param Application $app |
||
| 111 | * @param $groupId |
||
| 112 | * @param $file |
||
| 113 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function getGroupFile(Application $app, $groupId, $file) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * @param Application $app |
||
| 130 | * @param $file |
||
| 131 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function getUserFile(Application $app, $file) |
|
| 143 | } |
||
| 144 |