| Conditions | 8 |
| Paths | 49 |
| Total Lines | 65 |
| Code Lines | 41 |
| 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 |
||
| 48 | public function main(Request $request): Template |
||
| 49 | { |
||
| 50 | $this->logger::info('FIDO2 - Accessing Supercharged interface'); |
||
| 51 | |||
| 52 | $stateId = $request->query->get('StateId'); |
||
| 53 | if ($stateId === null) { |
||
| 54 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 55 | } |
||
| 56 | |||
| 57 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 58 | |||
| 59 | $templateFile = 'webauthn:supercharged.twig'; |
||
| 60 | |||
| 61 | // Make, populate and layout consent form |
||
| 62 | $t = new Template($this->config, $templateFile); |
||
| 63 | $t->data['UserID'] = $state['FIDO2Username']; |
||
| 64 | $t->data['FIDO2Tokens'] = $state['FIDO2Tokens']; |
||
| 65 | |||
| 66 | $challenge = str_split($state['FIDO2SignupChallenge'], 2); |
||
| 67 | $configUtils = new Utils\Config(); |
||
| 68 | $username = str_split( |
||
| 69 | hash('sha512', $state['FIDO2Username'] . '|' . $configUtils->getSecretSalt()), |
||
| 70 | 2 |
||
| 71 | ); |
||
| 72 | |||
| 73 | $challengeEncoded = []; |
||
| 74 | foreach ($challenge as $oneChar) { |
||
| 75 | $challengeEncoded[] = hexdec($oneChar); |
||
| 76 | } |
||
| 77 | |||
| 78 | $credentialIdEncoded = []; |
||
| 79 | foreach ($state['FIDO2Tokens'] as $number => $token) { |
||
| 80 | $idSplit = str_split($token[0], 2); |
||
| 81 | $credentialIdEncoded[$number] = []; |
||
| 82 | foreach ($idSplit as $credIdBlock) { |
||
| 83 | $credentialIdEncoded[$number][] = hexdec($credIdBlock); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $usernameEncoded = []; |
||
| 88 | foreach ($username as $oneChar) { |
||
| 89 | $usernameEncoded[] = hexdec($oneChar); |
||
| 90 | } |
||
| 91 | |||
| 92 | $frontendData = []; |
||
| 93 | $frontendData['challengeEncoded'] = $challengeEncoded; |
||
| 94 | $frontendData['state'] = []; |
||
| 95 | foreach (['FIDO2Scope','FIDO2Username','FIDO2Displayname','requestTokenModel'] as $stateItem) { |
||
| 96 | $frontendData['state'][$stateItem] = $state[$stateItem]; |
||
| 97 | } |
||
| 98 | |||
| 99 | $t->data['showExitButton'] = !array_key_exists('Registration', $state); |
||
| 100 | $frontendData['usernameEncoded'] = $usernameEncoded; |
||
| 101 | $frontendData['attestation'] = $state['requestTokenModel'] ? "indirect" : "none"; |
||
| 102 | $frontendData['credentialIdEncoded'] = $credentialIdEncoded; |
||
| 103 | $frontendData['FIDO2PasswordlessAuthMode'] = $state['FIDO2PasswordlessAuthMode']; |
||
| 104 | $t->data['hasPreviouslyDonePasswordless'] = $_COOKIE['SuccessfullyUsedPasswordlessBefore'] ?? "NO"; |
||
| 105 | $t->data['frontendData'] = json_encode($frontendData); |
||
| 106 | |||
| 107 | $t->data['authForm'] = ""; |
||
| 108 | $t->data['authURL'] = Module::getModuleURL('webauthn/authprocess?StateId=' . urlencode($stateId)); |
||
| 109 | $t->data['pushbackURL'] = Module::getModuleURL('webauthn/pushbackuserpass?StateId=' . urlencode($stateId)); |
||
| 110 | |||
| 111 | // dynamically generate the JS code needed for token registration |
||
| 112 | return $t; |
||
| 113 | } |
||
| 115 |