Conditions | 4 |
Paths | 5 |
Total Lines | 54 |
Code Lines | 33 |
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 |
||
64 | #[Route( |
||
65 | path: '/second-factor/{secondFactorId}/self-vet', |
||
66 | name: 'ss_second_factor_self_vet', |
||
67 | methods: ['GET'], |
||
68 | )] |
||
69 | public function selfVet(string $secondFactorId): RedirectResponse |
||
70 | { |
||
71 | $this->logger->notice('Starting self vet proof of possession using higher or equal LoA token'); |
||
72 | $identity = $this->getUser()->getIdentity(); |
||
73 | |||
74 | if (!$this->selfVetMarshaller->isAllowed($identity, $secondFactorId)) { |
||
75 | throw $this->createNotFoundException(); |
||
76 | } |
||
77 | |||
78 | // Start with some assumptions that are overwritten with the correct values in the code below |
||
79 | $candidateSecondFactorLoa = $this->loaResolutionService->getLoaByLevel(Loa::LOA_SELF_VETTED); |
||
80 | $isSelfVetOfSatToken = false; |
||
81 | |||
82 | // Determine if we are dealing with a SelfVet action of a SAT token |
||
83 | if ($this->authorizationService->maySelfVetSelfAssertedTokens($identity)) { |
||
84 | $this->logger->notice('Determined we are self vetting a token using a self-asserted token'); |
||
85 | $isSelfVetOfSatToken = true; |
||
86 | } |
||
87 | |||
88 | // When a regular self-vet action is performed grab the candidate second factor loa from the SF projection |
||
89 | if (!$isSelfVetOfSatToken) { |
||
90 | $this->logger->notice('Determined we are self vetting a token using an identity vetted token'); |
||
91 | $candidateSecondFactor = $this->secondFactorService->findOneVerified($secondFactorId); |
||
92 | $candidateSecondFactorLoa = $this->secondFactorTypeService->getLevel( |
||
93 | new SecondFactorType($candidateSecondFactor->type), |
||
94 | new VettingType(VettingType::TYPE_SELF_VET) |
||
95 | ); |
||
96 | $candidateSecondFactorLoa = $this->loaResolutionService->getLoaByLevel($candidateSecondFactorLoa); |
||
97 | } |
||
98 | $this->logger->notice( |
||
99 | sprintf( |
||
100 | 'Creating AuthNRequest requiring a LoA %s or higher token for self vetting.', |
||
101 | $candidateSecondFactorLoa |
||
102 | ) |
||
103 | ); |
||
104 | $authenticationRequest = $this->authenticationRequestFactory->createSecondFactorTestRequest( |
||
105 | $identity->nameId, |
||
106 | $candidateSecondFactorLoa |
||
107 | ); |
||
108 | |||
109 | $this->requestStack->getSession()->set( |
||
110 | self::SELF_VET_SESSION_ID, |
||
111 | new SelfVetRequestId($authenticationRequest->getRequestId(), $secondFactorId) |
||
112 | ); |
||
113 | |||
114 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($authenticationRequest->getRequestId()); |
||
115 | $samlLogger->notice('Sending authentication request to the second factor only IdP'); |
||
116 | |||
117 | return $this->redirectBinding->createResponseFor($authenticationRequest); |
||
118 | } |
||
120 |