Conditions | 4 |
Paths | 4 |
Total Lines | 65 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
92 | public function verifyU2fAuthenticationAction(Request $request) |
||
93 | { |
||
94 | /** @var ResponseContext $responseContext */ |
||
95 | $context = $this->get( |
||
96 | $this->get('gateway.proxy.state_handler')->getResponseContextServiceId() |
||
97 | ); |
||
98 | $originalRequestId = $context->getInResponseTo(); |
||
99 | |||
100 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
101 | |||
102 | $selectedSecondFactor = $this->get('gateway.service.require_selected_factor') |
||
103 | ->requireSelectedSecondFactor($logger); |
||
104 | |||
105 | $logger->notice('Received sign response from device'); |
||
106 | |||
107 | /** @var AttributeBagInterface $session */ |
||
108 | $session = $this->get('gateway.session.u2f'); |
||
109 | $signRequest = $session->get('request'); |
||
110 | $signResponse = new SignResponse(); |
||
111 | |||
112 | $formAction = $this->generateUrl('gateway_verify_second_factor_u2f_verify_authentication'); |
||
113 | $form = $this |
||
114 | ->createForm( |
||
115 | 'surfnet_stepup_u2f_verify_device_authentication', |
||
116 | $signResponse, |
||
117 | ['sign_request' => $signRequest, 'action' => $formAction] |
||
118 | ) |
||
119 | ->handleRequest($request); |
||
120 | |||
121 | $cancelFormAction = $this->generateUrl('gateway_verify_second_factor_u2f_cancel_authentication'); |
||
122 | $cancelForm = |
||
123 | $this->createForm('gateway_cancel_second_factor_verification', null, ['action' => $cancelFormAction]); |
||
124 | |||
125 | if (!$form->isValid()) { |
||
126 | $logger->error('U2F authentication verification could not be started because device send illegal data'); |
||
127 | $this->addFlash('error', 'gateway.u2f.alert.error'); |
||
128 | |||
129 | return ['authenticationFailed' => true, 'cancelForm' => $cancelForm->createView()]; |
||
130 | } |
||
131 | |||
132 | $service = $this->get('surfnet_stepup_u2f_verification.service.u2f_verification'); |
||
133 | $result = $service->verifyAuthentication($signRequest, $signResponse); |
||
134 | |||
135 | if ($result->wasSuccessful()) { |
||
136 | $context->markSecondFactorVerified(); |
||
137 | $this->get('gateway.authentication_logger')->logSecondFactorAuthentication($originalRequestId); |
||
138 | |||
139 | $logger->info( |
||
140 | sprintf( |
||
141 | 'Marked U2F second factor "%s" as verified, forwarding to Saml Proxy to respond', |
||
142 | $selectedSecondFactor |
||
143 | ) |
||
144 | ); |
||
145 | |||
146 | return $this->forward($context->getResponseAction()); |
||
147 | } elseif ($result->didDeviceReportError()) { |
||
148 | $logger->error('U2F device reported error during authentication'); |
||
149 | $this->addFlash('error', 'gateway.u2f.alert.device_reported_an_error'); |
||
150 | } else { |
||
151 | $logger->error('U2F authentication verification failed'); |
||
152 | $this->addFlash('error', 'gateway.u2f.alert.error'); |
||
153 | } |
||
154 | |||
155 | return ['authenticationFailed' => true, 'cancelForm' => $cancelForm->createView()]; |
||
156 | } |
||
157 | |||
165 |