| Conditions | 5 |
| Paths | 5 |
| Total Lines | 56 |
| Code Lines | 34 |
| 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 |
||
| 14 | public function getSignUpForm(ServerRequestInterface $request, ResponseInterface $response, $args) |
||
| 15 | { |
||
| 16 | $this->logger->info("Fetch sign-up GET '/signup'"); |
||
| 17 | |||
| 18 | if (isset($_SESSION['userId'])) { |
||
| 19 | return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('home')); |
||
| 20 | } |
||
| 21 | |||
| 22 | $auth = $this->auth; |
||
| 23 | $slug = $auth->getAuthProviderSlug(); |
||
| 24 | |||
| 25 | try { |
||
| 26 | $auth->getSocialUserId(); |
||
| 27 | } catch (Exception $e) { |
||
| 28 | return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('login')); |
||
| 29 | } |
||
| 30 | |||
| 31 | $existingPendingUser = PendingUserQuery::create() |
||
| 32 | ->filterBySocialId($auth->getSocialUserId()) |
||
| 33 | ->filterBySource($slug) |
||
| 34 | ->findOne(); |
||
| 35 | |||
| 36 | if (!is_null($existingPendingUser)) { |
||
| 37 | $firstName = $existingPendingUser->getFirstName(); |
||
| 38 | |||
| 39 | // remove any fb auth tokens |
||
| 40 | session_unset(); |
||
| 41 | |||
| 42 | return $this->view->render($response, 'login-sign-up-complete.twig', [ |
||
| 43 | 'firstname' => $firstName, |
||
| 44 | ]); |
||
| 45 | } |
||
| 46 | |||
| 47 | $firstName = ''; |
||
| 48 | $lastName = ''; |
||
| 49 | $email = ''; |
||
| 50 | |||
| 51 | switch ($slug) { |
||
| 52 | case 'facebook': |
||
| 53 | $meta = $auth->getMeta(); |
||
| 54 | |||
| 55 | // Split first and last names from FB |
||
| 56 | $names = explode(' ', $meta['name'], 2); |
||
| 57 | |||
| 58 | $firstName = $names[0]; |
||
| 59 | $lastName = $names[1]; |
||
| 60 | $email = $meta['email']; |
||
| 61 | break; |
||
| 62 | } |
||
| 63 | |||
| 64 | return $this->view->render($response, 'login-sign-up.twig', [ |
||
| 65 | 'firstname' => $firstName, |
||
| 66 | 'lastname' => $lastName, |
||
| 67 | 'email' => $email, |
||
| 68 | ]); |
||
| 69 | } |
||
| 70 | |||
| 106 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.