| Conditions | 15 |
| Paths | 864 |
| Total Lines | 60 |
| Code Lines | 39 |
| 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 |
||
| 31 | protected function redirectTo($object) |
||
| 32 | { |
||
| 33 | $request = $this->getRequest(); |
||
| 34 | |||
| 35 | $url = false; |
||
| 36 | $params = []; |
||
| 37 | |||
| 38 | if ($object instanceof Item) { |
||
| 39 | if ($object->getParent() !== null) { |
||
| 40 | $itemId = $object->getParent()->getId(); |
||
| 41 | $params['list']['item'] = $itemId; |
||
| 42 | $params['create']['create-item'] = $itemId; |
||
| 43 | } |
||
| 44 | $menuId = $object->getMenu()->getId(); |
||
| 45 | $params['list']['menu'] = $menuId; |
||
| 46 | $params['create']['create-menu'] = $menuId; |
||
| 47 | } elseif ($object instanceof Menu) { |
||
| 48 | $menuId = $object->getId(); |
||
| 49 | $params['list']['menu'] = $menuId; |
||
| 50 | $params['create']['create-menu'] = $menuId; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (null !== $request->get('btn_update_and_list')) { |
||
| 54 | $url = $this->admin->generateUrl('list', $params['list']); |
||
| 55 | } elseif (null !== $request->get('btn_create_and_list')) { |
||
| 56 | $url = $this->admin->generateUrl('list', $params['list']); |
||
| 57 | } |
||
| 58 | |||
| 59 | if (null !== $request->get('btn_create_and_create')) { |
||
| 60 | if ($this->admin->hasActiveSubClass()) { |
||
| 61 | $params['create']['subclass'] = $request->get('subclass'); |
||
| 62 | } |
||
| 63 | $url = $this->admin->generateUrl('create', $params['create']); |
||
| 64 | } |
||
| 65 | |||
| 66 | if ($this->getRestMethod() === 'DELETE') { |
||
| 67 | if ($object instanceof Item) { |
||
| 68 | $url = $this->admin->generateUrl('list', $params['list']); |
||
| 69 | } else { |
||
| 70 | $router = $this->get('router'); |
||
| 71 | $url = $router->generate('admin_alpixel_menu_menu_list'); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | if (!$url) { |
||
| 76 | foreach (['edit', 'show'] as $route) { |
||
| 77 | if ($this->admin->hasRoute($route) && $this->admin->isGranted(strtoupper($route), $object)) { |
||
| 78 | $url = $this->admin->generateObjectUrl($route, $object); |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!$url) { |
||
| 85 | $router = $this->get('router'); |
||
| 86 | $url = $router->generate('admin_alpixel_menu_menu_list'); |
||
| 87 | } |
||
| 88 | |||
| 89 | return new RedirectResponse($url); |
||
| 90 | } |
||
| 91 | } |
||
| 92 |