| Conditions | 6 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 32 |
| 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 |
||
| 114 | public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, string $user = null, string $token = null) |
||
| 115 | { |
||
| 116 | if (!$this->allow_email_pw_reset) { |
||
| 117 | throw new AccessDeniedHttpException("The password reset via email is disabled!"); |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
||
| 121 | throw new AccessDeniedHttpException("You are already logged in, so you can not reset your password!"); |
||
| 122 | } |
||
| 123 | |||
| 124 | $data = ['username' => $user, 'token' => $token]; |
||
| 125 | $builder = $this->createFormBuilder($data); |
||
| 126 | $builder->add('username', TextType::class, [ |
||
| 127 | 'label' => $this->translator->trans('pw_reset.username') |
||
| 128 | ]); |
||
| 129 | $builder->add('token', TextType::class, [ |
||
| 130 | 'label' => $this->translator->trans('pw_reset.token') |
||
| 131 | ]); |
||
| 132 | $builder->add('new_password', RepeatedType::class, [ |
||
| 133 | 'type' => PasswordType::class, |
||
| 134 | 'first_options' => ['label' => 'user.settings.pw_new.label'], |
||
| 135 | 'second_options' => ['label' => 'user.settings.pw_confirm.label'], |
||
| 136 | 'invalid_message' => 'password_must_match', |
||
| 137 | 'constraints' => [new Length([ |
||
| 138 | 'min' => 6, |
||
| 139 | 'max' => 128, |
||
| 140 | ])], |
||
| 141 | ]); |
||
| 142 | |||
| 143 | $builder->add('submit', SubmitType::class, [ |
||
| 144 | 'label' => 'pw_reset.submit' |
||
| 145 | ]); |
||
| 146 | |||
| 147 | $form = $builder->getForm(); |
||
| 148 | $form->handleRequest($request); |
||
| 149 | |||
| 150 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 151 | $data = $form->getData(); |
||
| 152 | //Try to set the new password |
||
| 153 | $success = $passwordReset->setNewPassword($data['username'], $data['token'], $data['new_password']); |
||
| 154 | if (!$success) { |
||
| 155 | $this->addFlash('error', $this->translator->trans('pw_reset.new_pw.error')); |
||
| 156 | } else { |
||
| 157 | $this->addFlash('success', $this->translator->trans('pw_reset.new_pw.success')); |
||
| 158 | return $this->redirectToRoute('login'); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | |||
| 163 | return $this->render('security/pw_reset_new_pw.html.twig', [ |
||
| 164 | 'form' => $form->createView() |
||
| 165 | ]); |
||
| 176 |