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