Conditions | 6 |
Paths | 9 |
Total Lines | 63 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
78 | * @throws AccessDeniedException |
||
79 | */ |
||
80 | #[Route(path: '/second-factor/test', name: 'ss_second_factor_test', methods: ['GET'])] |
||
81 | public function testSecondFactor(): RedirectResponse |
||
82 | { |
||
83 | $this->logger->notice('Starting second factor test'); |
||
84 | |||
85 | $identity = $this->getUser()->getIdentity(); |
||
86 | |||
87 | $vettedSecondFactors = $this->secondFactorService->findVettedByIdentity($identity->id); |
||
88 | if (!$vettedSecondFactors || $vettedSecondFactors->getTotalItems() === 0) { |
||
89 | $this->logger->error( |
||
90 | sprintf( |
||
91 | 'Identity "%s" tried to test a second factor, but does not own a suitable vetted token.', |
||
92 | $identity->id, |
||
93 | ), |
||
94 | ); |
||
95 | |||
96 | throw new NotFoundHttpException(); |
||
97 | } |
||
98 | |||
99 | |||
100 | // By requesting LoA 1.5 any relevant token can be tested (LoA 2 and 3) |
||
101 | $authenticationRequest = $this->testAuthenticationRequestFactory->createSecondFactorTestRequest( |
||
102 | $identity->nameId, |
||
103 | $this->loaResolutionService->getLoaByLevel(Loa::LOA_SELF_VETTED), |
||
104 | ); |
||
105 | |||
106 | $this->requestStack->getSession()->set('second_factor_test_request_id', $authenticationRequest->getRequestId()); |
||
107 | |||
108 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($authenticationRequest->getRequestId()); |
||
109 | $samlLogger->notice('Sending authentication request to the second factor test IDP'); |
||
110 | |||
111 | return $this->redirectBinding->createResponseFor($authenticationRequest); |
||
112 | } |
||
113 | |||
114 | #[Route( |
||
115 | path: '/authentication/consume-assertion', |
||
116 | name: 'selfservice_serviceprovider_consume_assertion', |
||
117 | methods: ['POST'], |
||
118 | )] |
||
119 | public function consumeAssertion(Request $httpRequest): Response |
||
120 | { |
||
121 | $session = $this->requestStack->getSession(); |
||
122 | if ($session->has(SelfVetController::SELF_VET_SESSION_ID)) { |
||
123 | // The test authentication IdP is also used for self vetting, a different session id is |
||
124 | // used to mark a self vet command |
||
125 | /** @var SelfVetRequestId $selfVetRequestId */ |
||
126 | $selfVetRequestId = $session->get(SelfVetController::SELF_VET_SESSION_ID); |
||
127 | $secondFactorId = $selfVetRequestId->vettingSecondFactorId(); |
||
128 | return $this->forward( |
||
129 | 'Surfnet\StepupSelfService\SelfServiceBundle\Controller\SelfVetController::consumeSelfVetAssertion', |
||
130 | ['secondFactorId' => $secondFactorId], |
||
131 | ); |
||
132 | } |
||
133 | if ($session->has(RecoveryTokenState::RECOVERY_TOKEN_STEP_UP_REQUEST_ID_IDENTIFIER)) { |
||
134 | // The test authentication IdP is also used for self-asserted recovery token |
||
135 | // verification a different session id is used to mark the authentication. |
||
136 | return $this->forward('Surfnet\StepupSelfService\SelfServiceBundle\Controller\RecoveryTokenController::stepUpConsumeAssertion'); |
||
137 | } |
||
138 | if (!$session->has('second_factor_test_request_id')) { |
||
139 | $this->logger->error( |
||
140 | 'Received an authentication response for testing a second factor, but no second factor test response was expected', |
||
141 | ); |
||
185 |