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