| Conditions | 8 |
| Paths | 7 |
| Total Lines | 87 |
| 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 |
||
| 166 | public function reset(Request $request, $reset_key) |
||
| 167 | { |
||
| 168 | if ($this->isGranted('ROLE_USER')) { |
||
| 169 | throw new HttpException\NotFoundHttpException(); |
||
| 170 | } |
||
| 171 | |||
| 172 | $errors = $this->validator->validate( |
||
| 173 | $reset_key, |
||
| 174 | [ |
||
| 175 | new Assert\NotBlank(), |
||
| 176 | new Assert\Regex( |
||
| 177 | [ |
||
| 178 | 'pattern' => '/^[a-zA-Z0-9]+$/', |
||
| 179 | ] |
||
| 180 | ), |
||
| 181 | ] |
||
| 182 | ); |
||
| 183 | |||
| 184 | if (count($errors) > 0 ) { |
||
| 185 | // リセットキーに以上がある場合 |
||
| 186 | throw new HttpException\NotFoundHttpException(); |
||
| 187 | } |
||
| 188 | |||
| 189 | $Customer = $this->customerRepository |
||
| 190 | ->getRegularCustomerByResetKey($reset_key); |
||
| 191 | |||
| 192 | if (null === $Customer) { |
||
| 193 | // リセットキーから会員データが取得できない場合 |
||
| 194 | throw new HttpException\NotFoundHttpException(); |
||
| 195 | } |
||
| 196 | |||
| 197 | $builder = $this->formFactory |
||
| 198 | ->createNamedBuilder('', PassowrdResetType::class); |
||
| 199 | |||
| 200 | $form = $builder->getForm(); |
||
| 201 | $form->handleRequest($request); |
||
| 202 | $error = null; |
||
| 203 | |||
| 204 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 205 | // リセットキー・入力メールアドレスで会員情報検索 |
||
| 206 | $Customer = $this->customerRepository |
||
| 207 | ->getRegularCustomerByResetKey($reset_key, $form->get('login_email')->getData()); |
||
| 208 | if ($Customer) { |
||
| 209 | // パスワードの発行・更新 |
||
| 210 | $encoder = $this->encoderFactory->getEncoder($Customer); |
||
| 211 | $pass = $form->get('password')->getData(); |
||
| 212 | $Customer->setPassword($pass); |
||
| 213 | |||
| 214 | // 発行したパスワードの暗号化 |
||
| 215 | if ($Customer->getSalt() === null) { |
||
| 216 | $Customer->setSalt($this->encoderFactory->getEncoder($Customer)->createSalt()); |
||
| 217 | } |
||
| 218 | $encPass = $encoder->encodePassword($pass, $Customer->getSalt()); |
||
| 219 | |||
| 220 | // パスワードを更新 |
||
| 221 | $Customer->setPassword($encPass); |
||
| 222 | // リセットキーをクリア |
||
| 223 | $Customer->setResetKey(null); |
||
| 224 | |||
| 225 | // パスワードを更新 |
||
| 226 | $this->entityManager->persist($Customer); |
||
| 227 | $this->entityManager->flush(); |
||
| 228 | |||
| 229 | $event = new EventArgs( |
||
| 230 | [ |
||
| 231 | 'Customer' => $Customer, |
||
| 232 | ], |
||
| 233 | $request |
||
| 234 | ); |
||
| 235 | $this->eventDispatcher->dispatch(EccubeEvents::FRONT_FORGOT_RESET_COMPLETE, $event); |
||
| 236 | |||
| 237 | // 完了メッセージを設定 |
||
| 238 | $this->addFlash('password_reset_complete', trans('front.forgot.reset_complete')); |
||
| 239 | |||
| 240 | // ログインページへリダイレクト |
||
| 241 | return $this->redirectToRoute('mypage_login'); |
||
| 242 | } else { |
||
| 243 | // リセットキー・メールアドレスから会員データが取得できない場合 |
||
| 244 | $error = trans('front.forgot.reset_not_found'); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | return [ |
||
| 249 | 'error' => $error, |
||
| 250 | 'form' => $form->createView(), |
||
| 251 | ]; |
||
| 252 | } |
||
| 253 | } |
||
| 254 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.