| Conditions | 6 |
| Paths | 32 |
| Total Lines | 64 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 112 | public function main(/** @scrutinizer ignore-unused */ Request $request): RunnableResponse |
||
| 113 | { |
||
| 114 | $moduleConfig = Configuration::getOptionalConfig('module_webauthn.php'); |
||
| 115 | $registrationConfig = $moduleConfig->getArray('registration'); |
||
| 116 | $registrationAuthSource = $registrationConfig['auth_source'] ?? 'default-sp'; |
||
| 117 | |||
| 118 | /** @psalm-var class-string $authSimple */ |
||
| 119 | $authSimple = $this->authSimple; |
||
| 120 | $as = new $authSimple($registrationAuthSource); |
||
| 121 | $as->requireAuth(); |
||
| 122 | $attrs = $as->getAttributes(); |
||
| 123 | |||
| 124 | $state = []; |
||
| 125 | $state['Attributes'] = $attrs; |
||
| 126 | |||
| 127 | $stateData = new StateData(); |
||
| 128 | $stateData->requestTokenModel = ($registrationConfig['policy_2fa']['minimum_certification_level'] == "0" ? false : true); |
||
| 129 | $stateData->minCertLevel2FA = $registrationConfig['policy_2fa']['minimum_certification_level']; |
||
| 130 | $stateData->aaguidWhitelist2FA = $registrationConfig['policy_2fa']['aaguid_whitelist']; |
||
| 131 | $stateData->attFmtWhitelist2FA = $registrationConfig['policy_2fa']['attestation_format_whitelist']; |
||
| 132 | $stateData->minCertLevelPasswordless = $registrationConfig['policy_passwordless']['minimum_certification_level']; |
||
| 133 | $stateData->aaguidWhitelistPasswordless = $registrationConfig['policy_passwordless']['aaguid_whitelist']; |
||
| 134 | $stateData->attFmtWhitelistPasswordless = $registrationConfig['policy_passwordless']['attestation_format_whitelist']; |
||
| 135 | $stateData->requestTokenModel = ($registrationConfig['minimum_certification_level'] == "0" ? false : true); |
||
| 136 | $stateData->minCertLevel = $registrationConfig['minimum_certification_level']; |
||
|
|
|||
| 137 | $stateData->aaguidWhitelist = $registrationConfig['aaguid_whitelist']; |
||
| 138 | $stateData->attFmtWhitelist = $registrationConfig['attestation_format_whitelist']; |
||
| 139 | |||
| 140 | try { |
||
| 141 | $stateData->store = Store::parseStoreConfig($moduleConfig->getArray('store')); |
||
| 142 | } catch (Exception $e) { |
||
| 143 | $this->logger::error( |
||
| 144 | 'webauthn: Could not create storage: ' . $e->getMessage() |
||
| 145 | ); |
||
| 146 | } |
||
| 147 | |||
| 148 | $stateData->scope = $moduleConfig->getOptionalString('scope', null); |
||
| 149 | $httpUtils = new Utils\HTTP(); |
||
| 150 | $baseurl = $httpUtils->getSelfHost(); |
||
| 151 | $hostname = parse_url($baseurl, PHP_URL_HOST); |
||
| 152 | if ($hostname !== null) { |
||
| 153 | $stateData->derivedScope = $hostname; |
||
| 154 | } |
||
| 155 | $stateData->usernameAttrib = $moduleConfig->getString('identifyingAttribute'); |
||
| 156 | $stateData->displaynameAttrib = $moduleConfig->getString('attrib_displayname'); |
||
| 157 | |||
| 158 | StaticProcessHelper::prepareState($stateData, $state); |
||
| 159 | |||
| 160 | $metadataHandler = MetaDataStorageHandler::getMetadataHandler(); |
||
| 161 | $metadata = $metadataHandler->getMetaDataCurrent('saml20-idp-hosted'); |
||
| 162 | $state['Source'] = $metadata; |
||
| 163 | $state['IdPMetadata'] = $metadata; |
||
| 164 | // inflow users are not allowed to enter the Registration page. If they |
||
| 165 | // did, kill the session |
||
| 166 | $moduleConfig = Configuration::getOptionalConfig('module_webauthn.php')->toArray(); |
||
| 167 | |||
| 168 | if ($moduleConfig['registration']['use_inflow_registration']) { |
||
| 169 | throw new Exception("Attempt to access the stand-alone registration page in inflow mode!"); |
||
| 170 | } |
||
| 171 | |||
| 172 | $state['Registration'] = true; |
||
| 173 | $state['FIDO2WantsRegister'] = true; |
||
| 174 | |||
| 175 | return new RunnableResponse([StaticProcessHelper::class, 'saveStateAndRedirect'], [&$state]); |
||
| 176 | } |
||
| 178 |