Conditions | 5 |
Paths | 5 |
Total Lines | 76 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
29 | public function selectSecondFactorForVerificationAction() |
||
30 | { |
||
31 | /** @var ResponseContext $responseContext */ |
||
32 | $context = $this->get( |
||
33 | $this->get('gateway.proxy.state_handler')->getResponseContextServiceId() |
||
34 | ); |
||
35 | $originalRequestId = $context->getInResponseTo(); |
||
36 | |||
37 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
38 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
39 | $logger->notice('Determining which second factor to use...'); |
||
40 | |||
41 | $requiredLoa = $this |
||
42 | ->get('gateway.service.stepup_authentication') |
||
43 | ->resolveHighestRequiredLoa( |
||
44 | $context->getRequiredLoa(), |
||
45 | $context->getServiceProvider(), |
||
46 | $context->getAuthenticatingIdp() |
||
47 | ); |
||
48 | |||
49 | if ($requiredLoa === null) { |
||
50 | $logger->notice( |
||
51 | 'No valid required Loa can be determined, no authentication is possible, Loa cannot be given' |
||
52 | ); |
||
53 | |||
54 | return $this->forward('SurfnetStepupGatewayGatewayBundle:Failure:sendLoaCannotBeGiven'); |
||
55 | } else { |
||
56 | $logger->notice(sprintf('Determined that the required Loa is "%s"', $requiredLoa)); |
||
57 | } |
||
58 | |||
59 | if ($this->get('gateway.service.stepup_authentication')->isIntrinsicLoa($requiredLoa)) { |
||
60 | $this->get('gateway.authentication_logger')->logIntrinsicLoaAuthentication($originalRequestId); |
||
61 | |||
62 | return $this->forward($context->getResponseAction()); |
||
63 | } |
||
64 | |||
65 | $secondFactorCollection = $this |
||
66 | ->get('gateway.service.stepup_authentication') |
||
67 | ->determineViableSecondFactors($context->getIdentityNameId(), $requiredLoa); |
||
68 | |||
69 | if (count($secondFactorCollection) === 0) { |
||
70 | $logger->notice('No second factors can give the determined Loa'); |
||
71 | |||
72 | return $this->forward('SurfnetStepupGatewayGatewayBundle:Failure:sendLoaCannotBeGiven'); |
||
73 | } |
||
74 | |||
75 | // will be replaced by a second factor selection screen once we support multiple |
||
76 | /** @var \Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor $secondFactor */ |
||
77 | $secondFactor = $secondFactorCollection->first(); |
||
78 | // when multiple second factors are supported this should be moved into the |
||
79 | // StepUpAuthenticationService::determineViableSecondFactors and handled in a performant way |
||
80 | // currently keeping this here for visibility |
||
81 | if (!$this->get('gateway.service.whitelist')->contains($secondFactor->institution)) { |
||
82 | $logger->notice(sprintf( |
||
83 | 'Second factor "%s" is listed for institution "%s" which is not on the whitelist, sending Loa ' |
||
84 | . 'cannot be given response', |
||
85 | $secondFactor->secondFactorId, |
||
86 | $secondFactor->institution |
||
87 | )); |
||
88 | |||
89 | return $this->forward('SurfnetStepupGatewayGatewayBundle:Failure:sendLoaCannotBeGiven'); |
||
90 | } |
||
91 | |||
92 | $logger->notice(sprintf( |
||
93 | 'Found "%d" second factors, using second factor of type "%s"', |
||
94 | count($secondFactorCollection), |
||
95 | $secondFactor->secondFactorType |
||
96 | )); |
||
97 | |||
98 | $context->saveSelectedSecondFactor($secondFactor->secondFactorId); |
||
99 | |||
100 | $this->get('gateway.service.stepup_authentication')->clearSmsVerificationState(); |
||
101 | |||
102 | $route = 'gateway_verify_second_factor_' . strtolower($secondFactor->secondFactorType); |
||
103 | return $this->redirect($this->generateUrl($route)); |
||
104 | } |
||
105 | } |
||
106 |