| Conditions | 14 | 
| Paths | 3 | 
| Total Lines | 37 | 
| Code Lines | 20 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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  | 
            ||
| 18 | public function redirectToServiceAction(Request $request, $service)  | 
            ||
| 19 |     { | 
            ||
| 20 |         try { | 
            ||
| 21 |             $authorizationUrl = $this->container->get('hwi_oauth.security.oauth_utils')->getAuthorizationUrl($request, $service); | 
            ||
| 22 |         } catch (\RuntimeException $e) { | 
            ||
| 23 | throw new NotFoundHttpException($e->getMessage(), $e);  | 
            ||
| 24 | }  | 
            ||
| 25 | |||
| 26 |         $tenant = $this->get('ds_tenant.service.tenant')->getContext(); | 
            ||
| 27 |         $authorizationUrl .= urlencode('?tenant='.$tenant); | 
            ||
| 28 | |||
| 29 | // Check for a return path and store it before redirect  | 
            ||
| 30 |         if ($request->hasSession()) { | 
            ||
| 31 | // initialize the session for preventing SessionUnavailableException  | 
            ||
| 32 | $session = $request->getSession();  | 
            ||
| 33 | $session->start();  | 
            ||
| 34 | |||
| 35 |             foreach ($this->container->getParameter('hwi_oauth.firewall_names') as $providerKey) { | 
            ||
| 36 | $sessionKey = '_security.'.$providerKey.'.target_path';  | 
            ||
| 37 | $sessionKeyFailure = '_security.'.$providerKey.'.failed_target_path';  | 
            ||
| 38 | |||
| 39 |                 $param = $this->container->getParameter('hwi_oauth.target_path_parameter'); | 
            ||
| 40 |                 if (!empty($param) && $targetUrl = $request->get($param)) { | 
            ||
| 41 | $session->set($sessionKey, $targetUrl);  | 
            ||
| 42 | }  | 
            ||
| 43 | |||
| 44 |                 if ($this->container->getParameter('hwi_oauth.failed_use_referer') && !$session->has($sessionKeyFailure) && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $authorizationUrl) { | 
            ||
| 45 | $session->set($sessionKeyFailure, $targetUrl);  | 
            ||
| 46 | }  | 
            ||
| 47 | |||
| 48 |                 if ($this->container->getParameter('hwi_oauth.use_referer') && !$session->has($sessionKey) && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $authorizationUrl) { | 
            ||
| 49 | $session->set($sessionKey, $targetUrl);  | 
            ||
| 50 | }  | 
            ||
| 51 | }  | 
            ||
| 52 | }  | 
            ||
| 53 | |||
| 54 | return $this->redirect($authorizationUrl);  | 
            ||
| 55 | }  | 
            ||
| 57 |