| Conditions | 9 |
| Paths | 9 |
| Total Lines | 68 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 91 | public function main(Request $request): RunnableResponse |
||
| 92 | { |
||
| 93 | // if (session_status() != PHP_SESSION_ACTIVE) { |
||
| 94 | // session_cache_limiter('nocache'); |
||
| 95 | // } |
||
| 96 | |||
| 97 | $this->logger::info('FIDO2 - Accessing WebAuthn token management'); |
||
| 98 | |||
| 99 | $stateId = $request->request->get('StateId'); |
||
| 100 | if ($stateId === null) { |
||
| 101 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** @var array $state */ |
||
| 105 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 106 | |||
| 107 | if ($state['FIDO2AuthSuccessful'] === false) { |
||
| 108 | throw new Exception("Attempt to access the token management page unauthenticated."); |
||
| 109 | } |
||
| 110 | |||
| 111 | switch ($request->request->get('submit')) { |
||
| 112 | case "NEVERMIND": |
||
| 113 | $response = new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
| 114 | break; |
||
| 115 | case "DELETE": |
||
| 116 | $credId = $request->request->get('credId'); |
||
| 117 | if ($state['FIDO2AuthSuccessful'] == $credId) { |
||
| 118 | throw new Exception("Attempt to delete the currently used credential despite UI preventing this."); |
||
| 119 | } |
||
| 120 | |||
| 121 | $store = $state['webauthn:store']; |
||
| 122 | $store->deleteTokenData($credId); |
||
| 123 | |||
| 124 | if (array_key_exists('Registration', $state)) { |
||
| 125 | foreach ($state['FIDO2Tokens'] as $key => $value) { |
||
| 126 | if ($state['FIDO2Tokens'][$key][0] == $credId) { |
||
| 127 | unset($state['FIDO2Tokens'][$key]); |
||
| 128 | break; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | $response = new RunnableResponse([StaticProcessHelper::class, 'saveStateAndRedirect'], [$state]); |
||
| 133 | } else { |
||
| 134 | $response = new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
| 135 | } |
||
| 136 | break; |
||
| 137 | default: |
||
| 138 | throw new Exception("Unknown submit button state."); |
||
| 139 | } |
||
| 140 | |||
| 141 | $response->headers->set('Expires', 'Thu, 19 Nov 1981 08:52:00 GMT'); |
||
| 142 | $response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); |
||
| 143 | $response->headers->set('Pragma', 'no-cache'); |
||
| 144 | |||
| 145 | /** Symfony 5 style */ |
||
| 146 | /** |
||
| 147 | $response->setCache([ |
||
| 148 | 'must_revalidate' => true, |
||
| 149 | 'no_cache' => true, |
||
| 150 | 'no_store' => true, |
||
| 151 | 'no_transform' => false, |
||
| 152 | 'public' => false, |
||
| 153 | 'private' => false, |
||
| 154 | ]); |
||
| 155 | $response->setExpires(new DateTime('Thu, 19 Nov 1981 08:52:00 GMT')); |
||
| 156 | */ |
||
| 157 | |||
| 158 | return $response; |
||
| 159 | } |
||
| 161 |