| Conditions | 5 |
| Paths | 9 |
| Total Lines | 77 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 52 | public function admin(Request $request): Template |
||
|
|
|||
| 53 | { |
||
| 54 | $consentconfig = Configuration::getConfig('module_consentSimpleAdmin.php'); |
||
| 55 | |||
| 56 | $as = $consentconfig->getValue('auth'); |
||
| 57 | $as = new Auth\Simple($as); |
||
| 58 | $as->requireAuth(); |
||
| 59 | |||
| 60 | // Get all attributes |
||
| 61 | $attributes = $as->getAttributes(); |
||
| 62 | |||
| 63 | // Get user ID |
||
| 64 | $userid_attributename = $consentconfig->getOptionalValue('userid', 'eduPersonPrincipalName'); |
||
| 65 | |||
| 66 | if (empty($attributes[$userid_attributename])) { |
||
| 67 | throw new Exception(sprintf( |
||
| 68 | 'Could not generate useridentifier for storing consent. Attribute [%s] was not available.', |
||
| 69 | $userid_attributename, |
||
| 70 | )); |
||
| 71 | } |
||
| 72 | |||
| 73 | $userid = $attributes[$userid_attributename][0]; |
||
| 74 | |||
| 75 | // Get metadata storage handler |
||
| 76 | $metadata = MetaDataStorageHandler::getMetadataHandler(); |
||
| 77 | |||
| 78 | // Get IdP id and metadata |
||
| 79 | $idp_entityid = $as->getAuthData('saml:sp:IdP'); |
||
| 80 | if ($idp_entityid !== null) { |
||
| 81 | // From a remote idp (as bridge) |
||
| 82 | $idp_metadata = $metadata->getMetaData($idp_entityid, 'saml20-idp-remote'); |
||
| 83 | } else { |
||
| 84 | // from the local idp |
||
| 85 | $idp_entityid = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); |
||
| 86 | $idp_metadata = $metadata->getMetaData($idp_entityid, 'saml20-idp-hosted'); |
||
| 87 | } |
||
| 88 | |||
| 89 | Logger::debug('consentAdmin: IdP is [' . $idp_entityid . ']'); |
||
| 90 | |||
| 91 | $source = $idp_metadata['metadata-set'] . '|' . $idp_entityid; |
||
| 92 | |||
| 93 | // Parse consent config |
||
| 94 | $consent_storage = Store::parseStoreConfig($consentconfig->getValue('store')); |
||
| 95 | |||
| 96 | // Calc correct user ID hash |
||
| 97 | $hashed_user_id = Consent::getHashedUserID($userid, $source); |
||
| 98 | |||
| 99 | // Check if button with withdraw all consent was clicked |
||
| 100 | if (array_key_exists('withdraw', $_REQUEST)) { |
||
| 101 | Logger::info(sprintf( |
||
| 102 | 'consentAdmin: UserID [%s] has requested to withdraw all consents given...', |
||
| 103 | $hashed_user_id, |
||
| 104 | )); |
||
| 105 | |||
| 106 | $consent_storage->deleteAllConsents($hashed_user_id); |
||
| 107 | } |
||
| 108 | |||
| 109 | // Get all consents for user |
||
| 110 | $user_consent_list = $consent_storage->getConsents($hashed_user_id); |
||
| 111 | |||
| 112 | $consentServices = []; |
||
| 113 | foreach ($user_consent_list as $c) { |
||
| 114 | $consentServices[$c[1]] = 1; |
||
| 115 | } |
||
| 116 | |||
| 117 | Logger::debug(sprintf( |
||
| 118 | 'consentAdmin: no of consents [%d] no of services [%d]', |
||
| 119 | count($user_consent_list), |
||
| 120 | count($consentServices), |
||
| 121 | )); |
||
| 122 | |||
| 123 | // Init template |
||
| 124 | $t = new Template($this->config, 'consentSimpleAdmin:consentadmin.twig'); |
||
| 125 | $t->data['consentServices'] = count($consentServices); |
||
| 126 | $t->data['consents'] = count($user_consent_list); |
||
| 127 | |||
| 128 | return $t; |
||
| 129 | } |
||
| 131 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.