Conditions | 12 |
Paths | 13 |
Total Lines | 40 |
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 |
||
23 | public function onKernelRequest(RequestEvent $event): void |
||
24 | { |
||
25 | if (!$event->isMainRequest()) { |
||
26 | return; |
||
27 | } |
||
28 | |||
29 | $request = $event->getRequest(); |
||
30 | $route = $request->attributes->get('_route'); |
||
31 | |||
32 | if (null !== $route && false === $request->attributes->get('requires_license', false)) { |
||
33 | return; |
||
34 | } |
||
35 | |||
36 | if ('active' === $request->query->get('lic') || 'prod' !== $this->environment) { |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | // Checking for allowed users |
||
41 | try { |
||
42 | /** @var TenantInterface $user */ |
||
43 | $user = $this->tokenStorage->getToken()->getUser(); |
||
44 | |||
45 | if ($user instanceof TenantInterface && $user->isWhiteListed()) { |
||
46 | return; |
||
47 | } |
||
48 | |||
49 | $today = date('Y-m-d'); |
||
50 | |||
51 | foreach ($this->licenseAllowList as $allowed) { |
||
52 | if ($today <= $allowed['valid_till'] && $allowed['client_key'] === $user->getClientKey()) { |
||
53 | return; |
||
54 | } |
||
55 | } |
||
56 | } catch (\Throwable $e) { |
||
57 | // Do nothing |
||
58 | } |
||
59 | |||
60 | $url = $this->router->generate('atlassian_connect_unlicensed', $request->query->all()); |
||
61 | $response = new RedirectResponse($url); |
||
62 | $event->setResponse($response); |
||
63 | } |
||
65 |