| Conditions | 12 |
| Paths | 8 |
| Total Lines | 44 |
| Code Lines | 30 |
| 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 |
||
| 44 | public function onKernelRequestSiteOff(RequestEvent $event): void |
||
| 45 | { |
||
| 46 | if (!$this->maintenanceModeEnabled) { |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | if (!$event->isMainRequest()) { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | $response = $event->getResponse(); |
||
| 55 | $request = $event->getRequest(); |
||
| 56 | $this->router->getContext()->setBaseUrl($request->getBaseUrl()); |
||
| 57 | try { |
||
| 58 | $routeInfo = $this->router->match($request->getPathInfo()); |
||
| 59 | } catch (\Exception) { |
||
| 60 | return; |
||
| 61 | } |
||
| 62 | if ('nucleos_user_security_login' === $routeInfo['_route']) { |
||
| 63 | return; |
||
| 64 | } |
||
| 65 | if ($response instanceof PlainResponse |
||
| 66 | || $response instanceof JsonResponse |
||
| 67 | || $request->isXmlHttpRequest()) { |
||
| 68 | return; |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($this->security->isGranted('ROLE_ADMIN')) { |
||
| 72 | return; |
||
| 73 | } |
||
| 74 | |||
| 75 | $hasOnlyBasicAccess = !$this->security->isGranted('IS_AUTHENTICATED'); |
||
| 76 | if ($hasOnlyBasicAccess && $request->hasSession() && null !== $request->getSession()) { |
||
| 77 | $request->getSession()->invalidate(); // logout |
||
| 78 | } |
||
| 79 | $response = new PlainResponse(); |
||
| 80 | $response->headers->add(['HTTP/1.1 503 Service Unavailable']); |
||
| 81 | $response->setStatusCode(503); |
||
| 82 | $content = $this->twig->render('@Core/System/siteoff.html.twig', [ |
||
| 83 | 'reason' => $this->maintenanceReason, |
||
| 84 | ]); |
||
| 85 | $response->setContent($content); |
||
| 86 | $event->setResponse($response); |
||
| 87 | $event->stopPropagation(); |
||
| 88 | } |
||
| 90 |