| Conditions | 7 |
| Paths | 27 |
| Total Lines | 54 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 38 | public function datatableDataAction(Request $request) |
||
| 39 | { |
||
| 40 | $params = $request->query->all(); |
||
| 41 | |||
| 42 | $draw = $params['draw']; |
||
| 43 | $limit = $params['length']; |
||
| 44 | $offset = $params['start']; |
||
| 45 | $orderBy = [$params['columns'][$params['order'][0]['column']]['name'], $params['order'][0]['dir']]; |
||
| 46 | $criteria = explode(' ', $params['search']['value']); |
||
| 47 | |||
| 48 | $columnSearch = []; |
||
| 49 | foreach ($params['columns'] as $column) { |
||
| 50 | if (!empty($column['search']['value'])) { |
||
| 51 | $columnSearch[$column['name']] = $column['search']; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $em = $this->getDoctrine()->getManager(); |
||
| 56 | |||
| 57 | $items = $em->getRepository('XdaysaysayCoreBundle:Xdcc')->findLike($criteria, $orderBy, $limit, $offset, false, $columnSearch); |
||
| 58 | |||
| 59 | $datas = []; |
||
| 60 | $translator = $this->get('translator'); |
||
| 61 | foreach ($items as $item) { |
||
| 62 | $teams = $item->getTeams(); |
||
| 63 | $teamFinalNames = []; |
||
| 64 | foreach($teams as $team) { |
||
| 65 | $teamFinalNames[] = $team->getName(); |
||
| 66 | } |
||
| 67 | |||
| 68 | $xdccNames = $item->getXdccnames(); |
||
| 69 | $xdccFinalNames = []; |
||
| 70 | foreach($xdccNames as $xdccName) { |
||
| 71 | $xdccFinalNames[] = $xdccName->getName(); |
||
| 72 | } |
||
| 73 | |||
| 74 | $datas[] = [ |
||
| 75 | $item->getId(), |
||
| 76 | implode('<br>', $teamFinalNames), |
||
| 77 | $item->getServer()->getName(), |
||
| 78 | implode('<br>', $xdccFinalNames), |
||
| 79 | count($item->getPacks()), |
||
| 80 | $item->getVisible() ? $translator->trans('admin.common.yes', [], 'admin') : $translator->trans('admin.common.no', [], 'admin'), |
||
| 81 | '<a href="'.$this->generateUrl('xdaysaysay_admin_xdcc_edit', ['id' => $item->getId()]).'" class="btn btn-primary">'.$translator->trans('admin.common.action.edit', [], 'admin').'</a> |
||
| 82 | <a href="'.$this->generateUrl('xdaysaysay_admin_xdcc_delete_confirm', ['id' => $item->getId()]).'" class="btn btn-danger">'.$translator->trans('admin.common.action.delete', [], 'admin').'</a>', |
||
| 83 | ]; |
||
| 84 | } |
||
| 85 | |||
| 86 | $totalFiltered = $em->getRepository('XdaysaysayCoreBundle:Xdcc')->findLike($criteria, $orderBy, $limit, $offset, true, $columnSearch); |
||
| 87 | |||
| 88 | $total = $em->getRepository('XdaysaysayCoreBundle:Xdcc')->countAll(); |
||
| 89 | |||
| 90 | return new JsonResponse(['data' => $datas, "draw" => $draw, "recordsTotal" => $total, "recordsFiltered" => $totalFiltered]); |
||
| 91 | } |
||
| 92 | } |