| Conditions | 10 |
| Paths | 18 |
| Total Lines | 47 |
| Code Lines | 30 |
| 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 |
||
| 90 | public function main(Request $request): RunnableResponse |
||
| 91 | { |
||
| 92 | if (session_status() != PHP_SESSION_ACTIVE) { |
||
| 93 | session_cache_limiter('nocache'); |
||
| 94 | } |
||
| 95 | |||
| 96 | $this->logger::info('FIDO2 - Accessing WebAuthn token management'); |
||
| 97 | |||
| 98 | $stateId = $request->query->get('StateId'); |
||
| 99 | if ($stateId === null) { |
||
| 100 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 101 | } |
||
| 102 | |||
| 103 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 104 | |||
| 105 | if ($state['FIDO2AuthSuccessful'] === false) { |
||
| 106 | throw new Exception("Attempt to access the token management page unauthenticated."); |
||
| 107 | } |
||
| 108 | |||
| 109 | switch ($request->request->get('submit')) { |
||
| 110 | case "NEVERMIND": |
||
| 111 | return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
| 112 | break; |
||
|
|
|||
| 113 | case "DELETE": |
||
| 114 | $credId = $request->request->get('credId'); |
||
| 115 | if ($state['FIDO2AuthSuccessful'] == $credId) { |
||
| 116 | throw new Exception("Attempt to delete the currently used credential despite UI preventing this."); |
||
| 117 | } |
||
| 118 | |||
| 119 | $store = $state['webauthn:store']; |
||
| 120 | $store->deleteTokenData($credId); |
||
| 121 | |||
| 122 | if (array_key_exists('Registration', $state)) { |
||
| 123 | foreach ($state['FIDO2Tokens'] as $key => $value) { |
||
| 124 | if ($state['FIDO2Tokens'][$key][0] == $credId) { |
||
| 125 | unset($state['FIDO2Tokens'][$key]); |
||
| 126 | break; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | return new RunnableResponse([StaticProcessHelper::class, 'saveStateAndRedirect'], [$state]); |
||
| 131 | } else { |
||
| 132 | return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
| 133 | } |
||
| 134 | break; |
||
| 135 | default: |
||
| 136 | throw new Exception("Unknown submit button state."); |
||
| 137 | } |
||
| 140 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.