Conditions | 5 |
Paths | 5 |
Total Lines | 57 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
51 | |||
52 | $validator = new AuthValidator($formParam, $this->lang); |
||
53 | if ($validator->validate() === false) { |
||
54 | $this->addContext('errors', $validator->getErrors()); |
||
55 | |||
56 | return $this->viewResponse(); |
||
57 | } |
||
58 | |||
59 | $username = $formParam->getUsername(); |
||
60 | $password = $formParam->getPassword(); |
||
61 | |||
62 | $credentials = [ |
||
63 | 'username' => $username, |
||
64 | 'password' => $password, |
||
65 | ]; |
||
66 | |||
67 | try { |
||
68 | $this->authentication->login($credentials); |
||
69 | } catch (AuthenticationException $ex) { |
||
70 | $this->logger->error('Authentication error: {error}', [ |
||
71 | 'error' => $ex->getMessage() |
||
72 | ]); |
||
73 | |||
74 | $this->flash->setError('Authentication error. Please check your login and/or password.'); |
||
75 | |||
76 | return $this->viewResponse(); |
||
77 | } |
||
78 | |||
79 | $returnUrl = $this->routeHelper->generateUrl('home'); |
||
80 | if ($param->get('next')) { |
||
81 | $returnUrl = $param->get('next'); |
||
82 | } |
||
83 | |||
84 | return new RedirectResponse($returnUrl); |
||
85 | } |
||
86 | } |
||
87 |