Conditions | 6 |
Paths | 5 |
Total Lines | 66 |
Code Lines | 42 |
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 |
||
126 | public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher, ?string $user = null, ?string $token = null) |
||
127 | { |
||
128 | if (!$this->allow_email_pw_reset) { |
||
129 | throw new AccessDeniedHttpException('The password reset via email is disabled!'); |
||
130 | } |
||
131 | |||
132 | if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { |
||
133 | throw new AccessDeniedHttpException('You are already logged in, so you can not reset your password!'); |
||
134 | } |
||
135 | |||
136 | $data = [ |
||
137 | 'username' => $user, |
||
138 | 'token' => $token, |
||
139 | ]; |
||
140 | $builder = $this->createFormBuilder($data); |
||
141 | $builder->add('username', TextType::class, [ |
||
142 | 'label' => $this->translator->trans('pw_reset.username'), |
||
143 | 'disabled' => true, |
||
144 | ]); |
||
145 | $builder->add('token', TextType::class, [ |
||
146 | 'label' => $this->translator->trans('pw_reset.token'), |
||
147 | 'disabled' => true, |
||
148 | ]); |
||
149 | $builder->add('new_password', RepeatedType::class, [ |
||
150 | 'type' => PasswordType::class, |
||
151 | 'first_options' => [ |
||
152 | 'label' => 'user.settings.pw_new.label', |
||
153 | ], |
||
154 | 'second_options' => [ |
||
155 | 'label' => 'user.settings.pw_confirm.label', |
||
156 | ], |
||
157 | 'invalid_message' => 'password_must_match', |
||
158 | 'constraints' => [new Length([ |
||
159 | 'min' => 6, |
||
160 | 'max' => 128, |
||
161 | ])], |
||
162 | ]); |
||
163 | |||
164 | $builder->add('submit', SubmitType::class, [ |
||
165 | 'label' => 'pw_reset.submit', |
||
166 | ]); |
||
167 | |||
168 | $form = $builder->getForm(); |
||
169 | $form->handleRequest($request); |
||
170 | |||
171 | if ($form->isSubmitted() && $form->isValid()) { |
||
172 | $data = $form->getData(); |
||
173 | //Try to set the new password |
||
174 | $success = $passwordReset->setNewPassword($data['username'], $data['token'], $data['new_password']); |
||
175 | if (!$success) { |
||
176 | $this->addFlash('error', 'pw_reset.new_pw.error'); |
||
177 | } else { |
||
178 | $this->addFlash('success', 'pw_reset.new_pw.success'); |
||
179 | |||
180 | $repo = $em->getRepository(User::class); |
||
181 | $u = $repo->findOneBy(['name' => $data['username']]); |
||
182 | $event = new SecurityEvent($u); |
||
|
|||
183 | /** @var EventDispatcher $eventDispatcher */ |
||
184 | $eventDispatcher->dispatch($event, SecurityEvents::PASSWORD_RESET); |
||
185 | |||
186 | return $this->redirectToRoute('login'); |
||
187 | } |
||
188 | } |
||
189 | |||
190 | return $this->renderForm('security/pw_reset_new_pw.html.twig', [ |
||
191 | 'form' => $form, |
||
192 | ]); |
||
203 |