| Conditions | 4 |
| Paths | 4 |
| Total Lines | 53 |
| Code Lines | 34 |
| 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 |
||
| 61 | public function process( |
||
| 62 | IAuthenticationProcess $process, |
||
| 63 | ?ServerRequestInterface $httpRequest |
||
| 64 | ): IChallengeResponse { |
||
| 65 | $form = $this |
||
| 66 | ->formFactory |
||
| 67 | ->createBuilder() |
||
| 68 | ->add('password', RepeatedType::class, [ |
||
| 69 | 'constraints' => [ |
||
| 70 | $this->constraint, |
||
| 71 | ], |
||
| 72 | 'type' => PasswordType::class, |
||
| 73 | 'invalid_message' => 'The password fields must match.', |
||
| 74 | 'required' => true, |
||
| 75 | 'first_options' => ['label' => 'Password'], |
||
| 76 | 'second_options' => ['label' => 'Repeat Password'], |
||
| 77 | ]) |
||
| 78 | ->add('submit', SubmitType::class) |
||
| 79 | ->getForm() |
||
| 80 | ; |
||
| 81 | |||
| 82 | if (null !== $httpRequest) { |
||
| 83 | $form->handleRequest($this->httpFoundationFactory->createRequest($httpRequest)); |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 87 | $newDm = $process |
||
|
|
|||
| 88 | ->getTypedMap() |
||
| 89 | ->add( |
||
| 90 | 'new_password', |
||
| 91 | password_hash($form->get('password')->getData(), PASSWORD_DEFAULT), |
||
| 92 | Scalar::_STR |
||
| 93 | ) |
||
| 94 | ; |
||
| 95 | |||
| 96 | return new ChallengeResponse( |
||
| 97 | new AuthenticationProcess($newDm), |
||
| 98 | null, |
||
| 99 | false, |
||
| 100 | true |
||
| 101 | ) |
||
| 102 | ; |
||
| 103 | } |
||
| 104 | |||
| 105 | $response = new Response($this->twig->render('password_update.html.twig', [ |
||
| 106 | 'form' => $form->createView(), |
||
| 107 | ])); |
||
| 108 | |||
| 109 | return new ChallengeResponse( |
||
| 110 | $process, |
||
| 111 | $response, |
||
| 112 | $form->isSubmitted(), |
||
| 113 | false |
||
| 114 | ) |
||
| 118 |