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