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