| Conditions | 6 |
| Paths | 8 |
| Total Lines | 53 |
| 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 |
||
| 58 | public function process( |
||
| 59 | IAuthenticationProcess $process, |
||
| 60 | ?ServerRequestInterface $httpRequest |
||
| 61 | ): IChallengeResponse { |
||
| 62 | $username = $process |
||
|
|
|||
| 63 | ->getTypedMap() |
||
| 64 | ->get('username', StringObject::class) |
||
| 65 | ->toString() |
||
| 66 | ; |
||
| 67 | |||
| 68 | $member = $this |
||
| 69 | ->appConfig |
||
| 70 | ->getMember($username) |
||
| 71 | ; |
||
| 72 | |||
| 73 | $form = $this |
||
| 74 | ->formFactory |
||
| 75 | ->createBuilder() |
||
| 76 | ->add('password', PasswordType::class) |
||
| 77 | ->add('submit', SubmitType::class) |
||
| 78 | ->getForm() |
||
| 79 | ; |
||
| 80 | |||
| 81 | if (null !== $httpRequest) { |
||
| 82 | $form->handleRequest($this->httpFoundationFactory->createRequest($httpRequest)); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($form->isSubmitted() && !password_verify($form['password']->getData(), $member->getHashedPassword())) { |
||
| 86 | $form |
||
| 87 | ->get('password') |
||
| 88 | ->addError(new FormError('The password is invalid.')) |
||
| 89 | ; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 93 | return new ChallengeResponse( |
||
| 94 | $process, |
||
| 95 | null, |
||
| 96 | false, |
||
| 97 | true |
||
| 98 | ) |
||
| 99 | ; |
||
| 100 | } |
||
| 101 | |||
| 102 | $response = new Response($this->twig->render("password_authentication.html.twig", [ |
||
| 103 | "form" => $form->createView(), |
||
| 104 | ])); |
||
| 105 | |||
| 106 | return new ChallengeResponse( |
||
| 107 | $process, |
||
| 108 | $response, |
||
| 109 | $form->isSubmitted(), |
||
| 110 | false |
||
| 111 | ) |
||
| 115 |