| Conditions | 10 |
| Paths | 14 |
| Total Lines | 41 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 74 | public function redirectToSettingsIfNeeded(RequestEvent $event) : void |
||
| 75 | { |
||
| 76 | $user = $this->security->getUser(); |
||
| 77 | $request = $event->getRequest(); |
||
| 78 | |||
| 79 | if(!$event->isMasterRequest()) { |
||
| 80 | return; |
||
| 81 | } |
||
| 82 | if(!$user instanceof User) { |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 86 | //Abort if we dont need to redirect the user. |
||
| 87 | if (!$user->isNeedPwChange() && !static::TFARedirectNeeded($user)) { |
||
| 88 | return; |
||
| 89 | } |
||
| 90 | |||
| 91 | //Check for a whitelisted URL |
||
| 92 | foreach (static::ALLOWED_ROUTES as $route) { |
||
| 93 | //Dont do anything if we encounter an allowed route |
||
| 94 | if ($this->httpUtils->checkRequestPath($request, $route)) { |
||
| 95 | return; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | /* Dont redirect tree endpoints, as this would cause trouble and creates multiple flash |
||
| 100 | warnigs for one page reload */ |
||
| 101 | if(strpos($request->getUri(), '/tree/') !== false) { |
||
| 102 | return; |
||
| 103 | } |
||
| 104 | |||
| 105 | //Show appropriate message to user about the reason he was redirected |
||
| 106 | if($user->isNeedPwChange()) { |
||
| 107 | $this->flashBag->add('warning', 'user.pw_change_needed.flash'); |
||
| 108 | } |
||
| 109 | |||
| 110 | if(static::TFARedirectNeeded($user)) { |
||
| 111 | $this->flashBag->add('warning', 'user.2fa_needed.flash'); |
||
| 112 | } |
||
| 113 | |||
| 114 | $event->setResponse($this->httpUtils->createRedirectResponse($request, static::REDIRECT_TARGET)); |
||
| 115 | |||
| 145 | } |