Conditions | 9 |
Paths | 9 |
Total Lines | 58 |
Code Lines | 39 |
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 |
||
77 | public function main(Request $request): RunnableResponse |
||
78 | { |
||
79 | $this->logger::info('FIDO2 - Accessing WebAuthn token management'); |
||
80 | |||
81 | $stateId = $request->query->get('StateId'); |
||
82 | if ($stateId === null) { |
||
83 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
84 | } |
||
85 | |||
86 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
87 | |||
88 | $ourState = WebAuthn::workflowStateMachine($state); |
||
|
|||
89 | if ($ourState !== WebAuthn::STATE_MGMT) { |
||
90 | throw new Exception("Attempt to access the token management page unauthenticated."); |
||
91 | } |
||
92 | |||
93 | switch ($request->request->get('submit')) { |
||
94 | case "NEVERMIND": |
||
95 | $response = new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
96 | break; |
||
97 | case "DELETE": |
||
98 | $credId = $request->request->get('credId'); |
||
99 | if ($state['FIDO2AuthSuccessful'] == $credId) { |
||
100 | throw new Exception("Attempt to delete the currently used credential despite UI preventing this."); |
||
101 | } |
||
102 | |||
103 | $store = $state['webauthn:store']; |
||
104 | $store->deleteTokenData($credId); |
||
105 | |||
106 | if (array_key_exists('Registration', $state)) { |
||
107 | foreach ($state['FIDO2Tokens'] as $key => $value) { |
||
108 | if ($state['FIDO2Tokens'][$key][0] == $credId) { |
||
109 | unset($state['FIDO2Tokens'][$key]); |
||
110 | $state['FIDO2Tokens'] = array_values($state['FIDO2Tokens']); |
||
111 | break; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | $response = new RunnableResponse([StaticProcessHelper::class, 'saveStateAndRedirect'], [&$state]); |
||
116 | } else { |
||
117 | $response = new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
118 | } |
||
119 | break; |
||
120 | default: |
||
121 | throw new Exception("Unknown submit button state."); |
||
122 | } |
||
123 | |||
124 | $response->setExpires(new DateTime('Thu, 19 Nov 1981 08:52:00 GMT')); |
||
125 | $response->setCache([ |
||
126 | 'must_revalidate' => true, |
||
127 | 'no_cache' => true, |
||
128 | 'no_store' => true, |
||
129 | 'no_transform' => false, |
||
130 | 'public' => false, |
||
131 | 'private' => false, |
||
132 | ]); |
||
133 | |||
134 | return $response; |
||
135 | } |
||
137 |