| Conditions | 11 | 
| Paths | 69 | 
| Total Lines | 89 | 
| Code Lines | 50 | 
| Lines | 4 | 
| Ratio | 4.49 % | 
| Changes | 4 | ||
| Bugs | 1 | Features | 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  | 
            ||
| 50 | public function onKernelRequest(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 51 |     { | 
            ||
| 52 |         if (!$event->getRequest()->headers->has('link')) { | 
            ||
| 53 | return;  | 
            ||
| 54 | }  | 
            ||
| 55 | |||
| 56 | $links = [];  | 
            ||
| 57 |         $header = $event->getRequest()->headers->get('link'); | 
            ||
| 58 | |||
| 59 | /*  | 
            ||
| 60 | * Due to limitations, multiple same-name headers are sent as comma  | 
            ||
| 61 | * separated values.  | 
            ||
| 62 | *  | 
            ||
| 63 | * This breaks those headers into Link headers following the format  | 
            ||
| 64 | * http://tools.ietf.org/html/rfc2068#section-19.6.2.4  | 
            ||
| 65 | */  | 
            ||
| 66 |         while (preg_match('/^((?:[^"]|"[^"]*")*?),/', $header, $matches)) { | 
            ||
| 67 | $header = trim(substr($header, strlen($matches[0])));  | 
            ||
| 68 | $links[] = $matches[1];  | 
            ||
| 69 | }  | 
            ||
| 70 | |||
| 71 |         if ($header) { | 
            ||
| 72 | $links[] = $header;  | 
            ||
| 73 | }  | 
            ||
| 74 | |||
| 75 | $requestMethod = $this->urlMatcher->getContext()->getMethod();  | 
            ||
| 76 | |||
| 77 | // The controller resolver needs a request to resolve the controller.  | 
            ||
| 78 | $stubRequest = new Request();  | 
            ||
| 79 | |||
| 80 |         foreach ($links as $idx => $link) { | 
            ||
| 81 | // Force the GET method to avoid the use of the previous method (LINK/UNLINK)  | 
            ||
| 82 |             $this->urlMatcher->getContext()->setMethod('GET'); | 
            ||
| 83 | |||
| 84 |             $linkParams = explode(';', trim($link)); | 
            ||
| 85 | $resourceType = null;  | 
            ||
| 86 | View Code Duplication |             if (count($linkParams) > 1) { | 
            |
| 87 |                 $resourceType = trim(preg_replace('/<|>/', '', $linkParams[1])); | 
            ||
| 88 |                 $resourceType = str_replace('"', '', str_replace('rel=', '', $resourceType)); | 
            ||
| 89 | }  | 
            ||
| 90 | $resource = array_shift($linkParams);  | 
            ||
| 91 |             $resource = preg_replace('/<|>/', '', $resource); | 
            ||
| 92 | $tempRequest = Request::create($resource);  | 
            ||
| 93 | |||
| 94 |             try { | 
            ||
| 95 | $route = $this->urlMatcher->match($tempRequest->getRequestUri());  | 
            ||
| 96 |             } catch (\Exception $e) { | 
            ||
| 97 | // If we don't have a matching route we return the original Link header  | 
            ||
| 98 | continue;  | 
            ||
| 99 | }  | 
            ||
| 100 | |||
| 101 | $stubRequest->attributes->replace($route);  | 
            ||
| 102 | $stubRequest->server = $event->getRequest()->server;  | 
            ||
| 103 |             if (false === $controller = $this->resolver->getController($stubRequest)) { | 
            ||
| 104 | continue;  | 
            ||
| 105 | }  | 
            ||
| 106 | |||
| 107 | $subEvent = new FilterControllerEvent($event->getKernel(), $controller, $stubRequest, HttpKernelInterface::SUB_REQUEST);  | 
            ||
| 108 | $kernelSubEvent = new GetResponseEvent($event->getKernel(), $stubRequest, HttpKernelInterface::SUB_REQUEST);  | 
            ||
| 109 | $dispatcher->dispatch(KernelEvents::REQUEST, $kernelSubEvent);  | 
            ||
| 110 | $dispatcher->dispatch(KernelEvents::CONTROLLER, $subEvent);  | 
            ||
| 111 | $controller = $subEvent->getController();  | 
            ||
| 112 | |||
| 113 | $arguments = $this->resolver->getArguments($stubRequest, $controller);  | 
            ||
| 114 |             if (!isset($arguments[0])) { | 
            ||
| 115 | continue;  | 
            ||
| 116 | }  | 
            ||
| 117 | |||
| 118 |             $arguments[0]->attributes->set('_link_request', true); | 
            ||
| 119 |             try { | 
            ||
| 120 | $result = call_user_func_array($controller, $arguments);  | 
            ||
| 121 | // Our api returns objects for single resources  | 
            ||
| 122 |                 if (!is_object($result)) { | 
            ||
| 123 | continue;  | 
            ||
| 124 | }  | 
            ||
| 125 | |||
| 126 | $links[$idx] = ['object' => $result, 'resourceType' => $resourceType];  | 
            ||
| 127 |             } catch (\Exception $e) { | 
            ||
| 128 | $links[$idx] = ['object' => $e, 'resourceType' => 'exception'];  | 
            ||
| 129 | |||
| 130 | continue;  | 
            ||
| 131 | }  | 
            ||
| 132 | }  | 
            ||
| 133 | |||
| 134 |         $event->getRequest()->attributes->set('links', $links); | 
            ||
| 135 | $this->urlMatcher->getContext()->setMethod($requestMethod);  | 
            ||
| 136 | |||
| 137 | return $links;  | 
            ||
| 138 | }  | 
            ||
| 139 | }  | 
            ||
| 140 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.