Conditions | 8 |
Paths | 12 |
Total Lines | 76 |
Code Lines | 48 |
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 |
||
63 | public function process( |
||
64 | IAuthenticationProcess $authenticationProcess, |
||
65 | ?ServerRequestInterface $httpRequest |
||
66 | ): IChallengeResponse { |
||
67 | $email = $authenticationProcess |
||
|
|||
68 | ->getTypedMap() |
||
69 | ->get('email', Scalar::_STR) |
||
70 | ; |
||
71 | |||
72 | $form = $this |
||
73 | ->formFactory |
||
74 | ->createBuilder() |
||
75 | ->add('emailCode') |
||
76 | ->add('submit', SubmitType::class) |
||
77 | ->getForm() |
||
78 | ; |
||
79 | |||
80 | if (null !== $httpRequest) { |
||
81 | $form->handleRequest( |
||
82 | $this->httpFoundationFactory->createRequest($httpRequest) |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | if ( |
||
87 | $form->isSubmitted() && |
||
88 | $form->isValid() && |
||
89 | null!== $httpRequest |
||
90 | ) { |
||
91 | $code = $authenticationProcess |
||
92 | ->getTypedMap() |
||
93 | ->get('email_code_hash', Scalar::_STR) |
||
94 | ; |
||
95 | $isCodeCorrect = password_verify( |
||
96 | $form['emailCode']->getData(), |
||
97 | $code |
||
98 | ); |
||
99 | if (true !== $isCodeCorrect) { |
||
100 | $form->addError(new FormError('The code you entered is incorrect')); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | if ($form->isSubmitted() && $form->isValid()) { |
||
105 | return new ChallengeResponse( |
||
106 | $authenticationProcess, |
||
107 | null, |
||
108 | false, |
||
109 | true |
||
110 | ) |
||
111 | ; |
||
112 | } |
||
113 | |||
114 | $code = random_int(self::CODE_MIN, self::CODE_MAX); |
||
115 | |||
116 | $email = $authenticationProcess |
||
117 | ->getTypedMap() |
||
118 | ->get('mailer', IMailer::class) |
||
119 | ->send($email, (string) $code) |
||
120 | ; |
||
121 | |||
122 | $response = new Response($this->twig->render('email.html.twig', [ |
||
123 | "form" => $form->createView(), |
||
124 | ])); |
||
125 | |||
126 | return new ChallengeResponse( |
||
127 | new AuthenticationProcess( |
||
128 | $authenticationProcess |
||
129 | ->getTypedMap() |
||
130 | ->set( |
||
131 | 'email_code_hash', |
||
132 | password_hash((string) $code, PASSWORD_DEFAULT), |
||
133 | Scalar::_STR |
||
134 | ) |
||
135 | ), |
||
136 | $response, |
||
137 | $form->isSubmitted(), |
||
138 | false |
||
139 | ) |
||
143 |