Conditions | 6 |
Paths | 5 |
Total Lines | 53 |
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 |
||
91 | public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, string $token = null): Response |
||
92 | { |
||
93 | if ($token) { |
||
94 | // We store the token in session and remove it from the URL, to avoid the URL being |
||
95 | // loaded in a browser and potentially leaking the token to 3rd party JavaScript. |
||
96 | $this->storeTokenInSession($token); |
||
97 | |||
98 | return $this->redirectToRoute('swp_user_reset_password'); |
||
99 | } |
||
100 | |||
101 | $token = $this->getTokenFromSession(); |
||
102 | if (null === $token) { |
||
103 | throw $this->createNotFoundException('No reset password token found in the URL or in the session.'); |
||
104 | } |
||
105 | |||
106 | try { |
||
107 | $user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); |
||
108 | } catch (ResetPasswordExceptionInterface $e) { |
||
109 | $this->addFlash('reset_password_error', sprintf( |
||
110 | 'There was a problem validating your reset request - %s', |
||
111 | $e->getReason() |
||
112 | )); |
||
113 | |||
114 | return $this->redirectToRoute('swp_user_forgot_password_request'); |
||
115 | } |
||
116 | |||
117 | // The token is valid; allow the user to change their password. |
||
118 | $form = $this->createForm(ChangePasswordFormType::class); |
||
119 | $form->handleRequest($request); |
||
120 | |||
121 | if ($form->isSubmitted() && $form->isValid()) { |
||
122 | // A password reset token should be used only once, remove it. |
||
123 | $this->resetPasswordHelper->removeResetRequest($token); |
||
124 | |||
125 | // Encode the plain password, and set it. |
||
126 | $encodedPassword = $passwordEncoder->encodePassword( |
||
127 | $user, |
||
128 | $form->get('plainPassword')->getData() |
||
129 | ); |
||
130 | |||
131 | $user->setPassword($encodedPassword); |
||
132 | $this->getDoctrine()->getManager()->flush(); |
||
133 | |||
134 | // The session is cleaned up after the password has been changed. |
||
135 | $this->cleanSessionAfterReset(); |
||
136 | |||
137 | return $this->redirectToRoute('homepage'); |
||
138 | } |
||
139 | |||
140 | return $this->render('@SWPUser/reset_password/reset.html.twig', [ |
||
141 | 'resetForm' => $form->createView(), |
||
142 | ]); |
||
143 | } |
||
144 | |||
175 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.