| Conditions | 15 |
| Paths | 102 |
| Total Lines | 45 |
| Lines | 24 |
| Ratio | 53.33 % |
| Changes | 0 | ||
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 |
||
| 110 | protected function redirectTo($object) |
||
| 111 | { |
||
| 112 | $request = $this->getRequest(); |
||
| 113 | |||
| 114 | $url = $backToNodeList = false; |
||
| 115 | $instanceAdmin = $this->admin->getConfigurationPool()->getInstance('alpixel_cms.admin.node'); |
||
| 116 | |||
| 117 | View Code Duplication | if (null !== $request->get('btn_update_and_list') || null !== $request->get('btn_create_and_list')) { |
|
| 118 | $backToNodeList = true; |
||
| 119 | } |
||
| 120 | |||
| 121 | View Code Duplication | if (null !== $request->get('btn_create_and_create')) { |
|
| 122 | $params = []; |
||
| 123 | if ($this->admin->hasActiveSubClass()) { |
||
| 124 | $params['subclass'] = $request->get('subclass'); |
||
| 125 | } |
||
| 126 | $url = $this->admin->generateUrl('create', $params); |
||
| 127 | } |
||
| 128 | |||
| 129 | View Code Duplication | if (null !== $request->get('btn_update_and_see_page') || null !== $request->get('btn_create_and_see_page')) { |
|
| 130 | return $this->redirectToRoute('alpixel_cms', [ |
||
| 131 | 'slug' => $object->getSlug(), |
||
| 132 | '_locale' => $object->getLocale(), |
||
| 133 | ]); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($this->getRestMethod() === 'DELETE') { |
||
| 137 | $backToNodeList = true; |
||
| 138 | } |
||
| 139 | |||
| 140 | View Code Duplication | if (!$url && !$backToNodeList) { |
|
| 141 | foreach (['edit', 'show'] as $route) { |
||
| 142 | if ($this->admin->hasRoute($route) && $this->admin->isGranted(strtoupper($route), $object)) { |
||
| 143 | $url = $this->admin->generateObjectUrl($route, $object); |
||
| 144 | break; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | if ($backToNodeList || !$url) { |
||
| 150 | $url = $instanceAdmin->generateUrl('list'); |
||
| 151 | } |
||
| 152 | |||
| 153 | return new RedirectResponse($url); |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.