| Conditions | 7 |
| Paths | 1 |
| Total Lines | 62 |
| 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 |
||
| 51 | public function connect(Application $app) |
||
| 52 | { |
||
| 53 | $this->app = $app; |
||
| 54 | |||
| 55 | /** @var ControllerCollection $controllers */ |
||
| 56 | $controllers = $app['controllers_factory']; |
||
| 57 | |||
| 58 | // handle the password reset form (display and saving) |
||
| 59 | $controllers->match('/reset/{token}', function (Application $app, Request $request, $token) { |
||
| 60 | $this->cleanupRequests(); |
||
| 61 | |||
| 62 | if ($this->validateRequest($token)) { |
||
| 63 | if ($request->isMethod('GET')) { |
||
| 64 | return $app['twig']->render('reset_password.twig', [ |
||
| 65 | 'reset_route' => $this->reset_route, |
||
| 66 | 'token' => $token |
||
| 67 | ]); |
||
| 68 | } elseif ($request->isMethod('POST')) { |
||
| 69 | $password = $request->request->get('password'); |
||
| 70 | $password_repeat = $request->request->get('password_repeat'); |
||
| 71 | if ($this->validateNewPassword($password, $password_repeat) === false) { |
||
| 72 | $app['session']->getFlashBag() |
||
| 73 | ->add('error', sprintf('Fehler beim Zurücksetzen des Passworts. Das gewählte Passwort muss aus mindestens %s Zeichen (Buchstaben, Ziffern *und* Sonderzeichen) bestehen.', $this->password_min_length)); |
||
| 74 | return $app->redirect($app['url_generator']->generate($this->reset_route, ['token' => $token])); |
||
| 75 | } else { |
||
| 76 | $details = $this->getRecoveryRequest($token); |
||
| 77 | $this->updatePassword($details['uid'], $password); |
||
| 78 | $this->closeRequest($token); |
||
| 79 | $app['session']->getFlashBag() |
||
| 80 | ->add('success', 'Dein Passwort wurde erfolgreich zurückgesetzt, du kannst dich jetzt einloggen.'); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } else { |
||
| 84 | $app['session']->getFlashBag() |
||
| 85 | ->add('error', 'Fehler beim Zurücksetzen des Passworts. Bitte versuche es noch einmal, oder benachrichtige das IT-Team.'); |
||
| 86 | } |
||
| 87 | return $app->redirect('/login'); |
||
| 88 | })->method('POST|GET'); |
||
| 89 | |||
| 90 | // handle the password request form to initiate a reset process |
||
| 91 | $controllers->match('/request', function (Application $app, Request $request) { |
||
| 92 | if ($request->isMethod('GET')) { |
||
| 93 | return $app['twig']->render('request_reset_password.twig', [ |
||
| 94 | 'request_route' => $this->request_route |
||
| 95 | ]); |
||
| 96 | } |
||
| 97 | $email = $request->request->get('email'); |
||
| 98 | $member = $app['ldap']->getMemberByMail($email); |
||
| 99 | if ($member !== false) { |
||
| 100 | $token = $this->registerRequest($member['uid'][0], $email); |
||
| 101 | $this->sendRecoveryMail($member, $token); |
||
| 102 | $app['session']->getFlashBag() |
||
| 103 | ->add('success', 'Wir haben dir einen Link zum Zurücksetzen deines Passworts zugeschickt. Bitte klicke auf diesen Link.'); |
||
| 104 | } else { |
||
| 105 | $app['session']->getFlashBag() |
||
| 106 | ->add('error', 'Diese Email-Adresse ist nicht vergeben.'); |
||
| 107 | } |
||
| 108 | return $app->redirect('/login'); |
||
| 109 | })->method('POST|GET'); |
||
| 110 | |||
| 111 | return $controllers; |
||
| 112 | } |
||
| 113 | |||
| 234 |