| Conditions | 14 |
| Paths | 193 |
| Total Lines | 74 |
| Code Lines | 45 |
| 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 |
||
| 88 | public function main(Request $request): Template |
||
| 89 | { |
||
| 90 | $this->logger::info('FIDO2 - Accessing WebAuthn interface'); |
||
| 91 | |||
| 92 | $stateId = $request->request->get('StateId'); |
||
| 93 | if ($stateId === null) { |
||
| 94 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** @var array $state */ |
||
| 98 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 99 | |||
| 100 | // Make, populate and layout consent form |
||
| 101 | $t = new Template($this->config, 'webauthn:authentication.twig'); |
||
| 102 | $t->data['UserID'] = $state['FIDO2Username']; |
||
| 103 | $t->data['FIDO2Tokens'] = $state['FIDO2Tokens']; |
||
| 104 | |||
| 105 | $challenge = str_split($state['FIDO2SignupChallenge'], 2); |
||
| 106 | $username = str_split( |
||
| 107 | hash('sha512', $state['FIDO2Username'] . '|' . Utils\Config::getSecretSalt() . '|' . $state['Source']['entityid']), |
||
| 108 | 2 |
||
| 109 | ); |
||
| 110 | |||
| 111 | $challengeEncoded = []; |
||
| 112 | foreach ($challenge as $oneChar) { |
||
| 113 | $challengeEncoded[] = hexdec($oneChar); |
||
| 114 | } |
||
| 115 | |||
| 116 | $credentialIdEncoded = []; |
||
| 117 | foreach ($state['FIDO2Tokens'] as $number => $token) { |
||
| 118 | $idSplit = str_split($token[0], 2); |
||
| 119 | $credentialIdEncoded[$number] = []; |
||
| 120 | foreach ($idSplit as $credIdBlock) { |
||
| 121 | $credentialIdEncoded[$number][] = hexdec($credIdBlock); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $usernameEncoded = []; |
||
| 126 | foreach ($username as $oneChar) { |
||
| 127 | $usernameEncoded[] = hexdec($oneChar); |
||
| 128 | } |
||
| 129 | |||
| 130 | $frontendData = []; |
||
| 131 | $frontendData['challengeEncoded'] = $challengeEncoded; |
||
| 132 | $frontendData['state'] = []; |
||
| 133 | foreach (['Source', 'FIDO2Scope','FIDO2Username','FIDO2Displayname','requestTokenModel'] as $stateItem) { |
||
| 134 | $frontendData['state'][$stateItem] = $state[$stateItem]; |
||
| 135 | } |
||
| 136 | |||
| 137 | $t->data['showExitButton'] = !array_key_exists('Registration', $state); |
||
| 138 | $frontendData['usernameEncoded'] = $usernameEncoded; |
||
| 139 | $frontendData['attestation'] = $state['requestTokenModel'] ? "indirect" : "none"; |
||
| 140 | $frontendData['credentialIdEncoded'] = $credentialIdEncoded; |
||
| 141 | $t->data['frontendData'] = json_encode($frontendData); |
||
| 142 | |||
| 143 | $t->data['FIDO2AuthSuccessful'] = $state['FIDO2AuthSuccessful']; |
||
| 144 | if ( |
||
| 145 | count($state['FIDO2Tokens']) == 0 || |
||
| 146 | ($state['FIDO2WantsRegister'] === true && $state['FIDO2AuthSuccessful'] !== false) |
||
| 147 | ) { |
||
| 148 | $t->data['regURL'] = Module::getModuleURL('webauthn/regprocess.php?StateId=' . urlencode($stateId)); |
||
| 149 | $t->data['delURL'] = Module::getModuleURL('webauthn/managetoken.php?StateId=' . urlencode($stateId)); |
||
| 150 | } |
||
| 151 | |||
| 152 | $t->data['authForm'] = ""; |
||
| 153 | if ( |
||
| 154 | count($state['FIDO2Tokens']) > 0 && |
||
| 155 | ($state['FIDO2WantsRegister'] !== true || $state['FIDO2AuthSuccessful'] === false) |
||
| 156 | ) { |
||
| 157 | $t->data['authURL'] = Module::getModuleURL('webauthn/authprocess.php?StateId=' . urlencode($stateId)); |
||
| 158 | } |
||
| 159 | |||
| 160 | // dynamically generate the JS code needed for token registration |
||
| 161 | return $t; |
||
| 162 | } |
||
| 164 |