Conditions | 6 |
Paths | 5 |
Total Lines | 78 |
Code Lines | 47 |
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 |
||
54 | #[Route( |
||
55 | path: '/registration/gssf/{provider}/consume-assertion', |
||
56 | name: 'ss_registration_gssf_consume_assertion', |
||
57 | methods: ['POST'], |
||
58 | )] |
||
59 | public function consumeAssertion(Request $httpRequest, string $provider): array|Response |
||
60 | { |
||
61 | $this->assertSecondFactorEnabled($provider); |
||
62 | |||
63 | $provider = $this->providerRepository->get($provider); |
||
64 | |||
65 | $this->logger->notice( |
||
66 | sprintf('Received GSSP "%s" SAMLResponse through Gateway, attempting to process', $provider->getName()) |
||
67 | ); |
||
68 | |||
69 | try { |
||
70 | $assertion = $this->postBinding->processResponse( |
||
71 | $httpRequest, |
||
72 | $provider->getRemoteIdentityProvider(), |
||
73 | $provider->getServiceProvider() |
||
74 | ); |
||
75 | } catch (Exception $exception) { |
||
76 | $provider->getStateHandler()->clear(); |
||
77 | |||
78 | $this->logger->error( |
||
79 | sprintf('Could not process received Response, error: "%s"', $exception->getMessage()) |
||
80 | ); |
||
81 | |||
82 | return $this->redirectToStatusReportForm( |
||
83 | $provider, |
||
84 | ['authenticationFailed' => true] |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | $expectedResponseTo = $provider->getStateHandler()->getRequestId(); |
||
89 | $provider->getStateHandler()->clear(); |
||
90 | |||
91 | if (!InResponseTo::assertEquals($assertion, $expectedResponseTo)) { |
||
92 | $this->logger->critical(sprintf( |
||
93 | 'Received Response with unexpected InResponseTo, %s', |
||
94 | ($expectedResponseTo ? 'expected "' . $expectedResponseTo . '"' : ' no response expected') |
||
95 | )); |
||
96 | |||
97 | return $this->redirectToStatusReportForm( |
||
98 | $provider, |
||
99 | ['authenticationFailed' => true] |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | $this->logger->notice( |
||
104 | sprintf('Processed GSSP "%s" SAMLResponse received through Gateway successfully', $provider->getName()) |
||
105 | ); |
||
106 | |||
107 | $gssfId = $this->attributeDictionary->translate($assertion)->getNameID(); |
||
108 | |||
109 | $secondFactorId = $this->gssfService->provePossession($this->getIdentity()->id, $provider->getName(), $gssfId); |
||
110 | |||
111 | if ($secondFactorId) { |
||
112 | $this->logger->notice('GSSF possession has been proven successfully'); |
||
113 | |||
114 | if ($this->emailVerificationIsRequired()) { |
||
115 | return $this->redirectToRoute( |
||
116 | 'ss_registration_email_verification_email_sent', |
||
117 | ['secondFactorId' => $secondFactorId] |
||
118 | ); |
||
119 | } else { |
||
120 | return $this->redirectToRoute( |
||
121 | 'ss_second_factor_vetting_types', |
||
122 | ['secondFactorId' => $secondFactorId] |
||
123 | ); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | $this->logger->error('Unable to prove GSSF possession'); |
||
128 | |||
129 | return $this->redirectToStatusReportForm( |
||
130 | $provider, |
||
131 | ['proofOfPossessionFailed' => true] |
||
132 | ); |
||
146 |