Conditions | 6 |
Paths | 5 |
Total Lines | 51 |
Code Lines | 26 |
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 |
||
80 | public function reset(Request $request, UserPasswordHasherInterface $passwordEncoder, string $token = null): Response |
||
81 | { |
||
82 | if ($token) { |
||
83 | // We store the token in session and remove it from the URL, to avoid the URL being |
||
84 | // loaded in a browser and potentially leaking the token to 3rd party JavaScript. |
||
85 | $this->storeTokenInSession($token); |
||
86 | |||
87 | return $this->redirectToRoute('app_reset_password'); |
||
88 | } |
||
89 | |||
90 | $token = $this->getTokenFromSession(); |
||
91 | if (null === $token) { |
||
92 | throw $this->createNotFoundException('No reset password token found in the URL or in the session.'); |
||
93 | } |
||
94 | |||
95 | try { |
||
96 | $user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); |
||
97 | } catch (ResetPasswordExceptionInterface $e) { |
||
98 | $this->addFlash('reset_password_error', sprintf( |
||
99 | 'There was a problem validating your reset request - %s', |
||
100 | $e->getReason() |
||
101 | )); |
||
102 | |||
103 | return $this->redirectToRoute('app_forgot_password_request'); |
||
104 | } |
||
105 | |||
106 | // The token is valid; allow the user to change their password. |
||
107 | $form = $this->createForm(ChangePasswordFormType::class); |
||
108 | $form->handleRequest($request); |
||
109 | |||
110 | if ($form->isSubmitted() && $form->isValid()) { |
||
111 | // A password reset token should be used only once, remove it. |
||
112 | $this->resetPasswordHelper->removeResetRequest($token); |
||
113 | |||
114 | // Encode the plain password, and set it. |
||
115 | $encodedPassword = $passwordEncoder->hashPassword( |
||
116 | $user, |
||
117 | $form->get('plainPassword')->getData() |
||
118 | ); |
||
119 | |||
120 | $user->setPassword($encodedPassword); |
||
121 | $this->getDoctrine()->getManager()->flush(); |
||
122 | |||
123 | // The session is cleaned up after the password has been changed. |
||
124 | $this->cleanSessionAfterReset(); |
||
125 | |||
126 | return $this->redirectToRoute('homepage'); |
||
127 | } |
||
128 | |||
129 | return $this->render('reset_password/reset.html.twig', [ |
||
130 | 'resetForm' => $form->createView(), |
||
131 | ]); |
||
179 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.