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 |
||
| 21 | class TaskController extends Controller |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @Route( |
||
| 25 | * ".{_format}", |
||
| 26 | * name="orocrm_task_index", |
||
| 27 | * requirements={"_format"="html|json"}, |
||
| 28 | * defaults={"_format" = "html"} |
||
| 29 | * ) |
||
| 30 | * @Acl( |
||
| 31 | * id="orocrm_task_view", |
||
| 32 | * type="entity", |
||
| 33 | * class="OroCRMTaskBundle:Task", |
||
| 34 | * permission="VIEW" |
||
| 35 | * ) |
||
| 36 | * @Template |
||
| 37 | */ |
||
| 38 | public function indexAction() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @Route("/widget/sidebar-tasks/{perPage}", name="orocrm_task_widget_sidebar_tasks", defaults={"perPage" = 10}) |
||
| 47 | * @AclAncestor("orocrm_task_view") |
||
| 48 | * @Template("OroCRMTaskBundle:Task/widget:tasksWidget.html.twig") |
||
| 49 | */ |
||
| 50 | public function tasksWidgetAction($perPage) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @Route("/create", name="orocrm_task_create") |
||
| 63 | * @Acl( |
||
| 64 | * id="orocrm_task_create", |
||
| 65 | * type="entity", |
||
| 66 | * class="OroCRMTaskBundle:Task", |
||
| 67 | * permission="CREATE" |
||
| 68 | * ) |
||
| 69 | * @Template("OroCRMTaskBundle:Task:update.html.twig") |
||
| 70 | */ |
||
| 71 | public function createAction() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return User |
||
| 88 | */ |
||
| 89 | protected function getCurrentUser() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @Route("/view/{id}", name="orocrm_task_view", requirements={"id"="\d+"}) |
||
| 98 | * @AclAncestor("orocrm_task_view") |
||
| 99 | * @Template |
||
| 100 | */ |
||
| 101 | public function viewAction(Task $task) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * This action is used to render the list of tasks associated with the given entity |
||
| 108 | * on the view page of this entity |
||
| 109 | * |
||
| 110 | * @Route( |
||
| 111 | * "/activity/view/{entityClass}/{entityId}", |
||
| 112 | * name="orocrm_task_activity_view" |
||
| 113 | * ) |
||
| 114 | * |
||
| 115 | * @AclAncestor("orocrm_task_view") |
||
| 116 | * @Template |
||
| 117 | */ |
||
| 118 | public function activityAction($entityClass, $entityId) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @Route("/update/{id}", name="orocrm_task_update", requirements={"id"="\d+"}) |
||
| 127 | * @Template |
||
| 128 | * @Acl( |
||
| 129 | * id="orocrm_task_update", |
||
| 130 | * type="entity", |
||
| 131 | * class="OroCRMTaskBundle:Task", |
||
| 132 | * permission="EDIT" |
||
| 133 | * ) |
||
| 134 | */ |
||
| 135 | public function updateAction(Task $task) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @Route("/widget/info/{id}", name="orocrm_task_widget_info", requirements={"id"="\d+"}) |
||
| 144 | * @Template |
||
| 145 | * @AclAncestor("orocrm_task_view") |
||
| 146 | */ |
||
| 147 | public function infoAction(Task $entity) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @Route("/user/{userId}", name="orocrm_task_user_tasks", requirements={"userId"="\d+"}) |
||
| 158 | * @AclAncestor("orocrm_task_view") |
||
| 159 | * @Template |
||
| 160 | */ |
||
| 161 | public function userTasksAction($userId) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @Route("/my", name="orocrm_task_my_tasks") |
||
| 168 | * @AclAncestor("orocrm_task_view") |
||
| 169 | * @Template |
||
| 170 | */ |
||
| 171 | public function myTasksAction() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param Task $task |
||
| 178 | * @param string $formAction |
||
| 179 | * @return array |
||
| 180 | */ |
||
| 181 | View Code Duplication | protected function update(Task $task, $formAction) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * @return TaskType |
||
| 206 | */ |
||
| 207 | protected function getFormType() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param string $entityName |
||
| 214 | * @return \Doctrine\Common\Persistence\ObjectRepository |
||
| 215 | */ |
||
| 216 | protected function getRepository($entityName) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Get target entity |
||
| 223 | * |
||
| 224 | * @return object|null |
||
| 225 | */ |
||
| 226 | View Code Duplication | protected function getTargetEntity() |
|
| 237 | } |
||
| 238 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.