| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 163 |
| Code Lines | 103 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 92 | public function getconsent(Request $request) |
||
| 93 | { |
||
| 94 | $this->logger::info('Consent - getconsent: Accessing consent interface'); |
||
| 95 | |||
| 96 | $stateId = $request->query->get('StateId'); |
||
| 97 | if ($stateId === null) { |
||
| 98 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 99 | } |
||
| 100 | |||
| 101 | $state = $this->authState::loadState($stateId, 'consent:request'); |
||
| 102 | |||
| 103 | if (is_null($state)) { |
||
| 104 | throw new Error\NoState(); |
||
| 105 | } elseif (array_key_exists('core:SP', $state)) { |
||
| 106 | $spentityid = $state['core:SP']; |
||
| 107 | } elseif (array_key_exists('saml:sp:State', $state)) { |
||
| 108 | $spentityid = $state['saml:sp:State']['core:SP']; |
||
| 109 | } else { |
||
| 110 | $spentityid = 'UNKNOWN'; |
||
| 111 | } |
||
| 112 | |||
| 113 | // The user has pressed the yes-button |
||
| 114 | if ($request->query->get('yes') !== null) { |
||
| 115 | if ($request->query->get('saveconsent') !== null) { |
||
| 116 | $this->logger::stats('consentResponse remember'); |
||
| 117 | } else { |
||
| 118 | $this->logger::stats('consentResponse rememberNot'); |
||
| 119 | } |
||
| 120 | |||
| 121 | $statsInfo = [ |
||
| 122 | 'remember' => $request->query->get('saveconsent'), |
||
| 123 | ]; |
||
| 124 | if (isset($state['Destination']['entityid'])) { |
||
| 125 | $statsInfo['spEntityID'] = $state['Destination']['entityid']; |
||
| 126 | } |
||
| 127 | Stats::log('consent:accept', $statsInfo); |
||
| 128 | |||
| 129 | if ( |
||
| 130 | array_key_exists('consent:store', $state) |
||
| 131 | && $request->query->get('saveconsent') === '1' |
||
| 132 | ) { |
||
| 133 | // Save consent |
||
| 134 | $store = $state['consent:store']; |
||
| 135 | $userId = $state['consent:store.userId']; |
||
| 136 | $targetedId = $state['consent:store.destination']; |
||
| 137 | $attributeSet = $state['consent:store.attributeSet']; |
||
| 138 | |||
| 139 | $this->logger::debug( |
||
| 140 | 'Consent - saveConsent() : [' . $userId . '|' . $targetedId . '|' . $attributeSet . ']' |
||
| 141 | ); |
||
| 142 | try { |
||
| 143 | $store->saveConsent($userId, $targetedId, $attributeSet); |
||
| 144 | } catch (Exception $e) { |
||
| 145 | $this->logger::error('Consent: Error writing to storage: ' . $e->getMessage()); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
| 150 | } |
||
| 151 | |||
| 152 | // Prepare attributes for presentation |
||
| 153 | $attributes = $state['Attributes']; |
||
| 154 | $noconsentattributes = $state['consent:noconsentattributes']; |
||
| 155 | |||
| 156 | // Remove attributes that do not require consent |
||
| 157 | foreach ($attributes as $attrkey => $attrval) { |
||
| 158 | if (in_array($attrkey, $noconsentattributes, true)) { |
||
| 159 | unset($attributes[$attrkey]); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | $para = [ |
||
| 163 | 'attributes' => &$attributes |
||
| 164 | ]; |
||
| 165 | |||
| 166 | // Reorder attributes according to attributepresentation hooks |
||
| 167 | Module::callHooks('attributepresentation', $para); |
||
| 168 | |||
| 169 | // Unset the values for attributes that need to be hidden |
||
| 170 | if (array_key_exists('consent:hiddenAttributes', $state)) { |
||
| 171 | foreach ($state['consent:hiddenAttributes'] as $hidden) { |
||
| 172 | if (array_key_exists($hidden, $attributes)) { |
||
| 173 | $attributes[$hidden] = null; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | // Parse parameters |
||
| 179 | if (array_key_exists('name', $state['Source'])) { |
||
| 180 | $srcName = $state['Source']['name']; |
||
| 181 | } elseif (array_key_exists('OrganizationDisplayName', $state['Source'])) { |
||
| 182 | $srcName = $state['Source']['OrganizationDisplayName']; |
||
| 183 | } else { |
||
| 184 | $srcName = $state['Source']['entityid']; |
||
| 185 | } |
||
| 186 | |||
| 187 | if (array_key_exists('name', $state['Destination'])) { |
||
| 188 | $dstName = $state['Destination']['name']; |
||
| 189 | } elseif (array_key_exists('OrganizationDisplayName', $state['Destination'])) { |
||
| 190 | $dstName = $state['Destination']['OrganizationDisplayName']; |
||
| 191 | } else { |
||
| 192 | $dstName = $state['Destination']['entityid']; |
||
| 193 | } |
||
| 194 | |||
| 195 | // Make, populate and layout consent form |
||
| 196 | $t = new Template($this->config, 'consent:consentform.twig'); |
||
| 197 | $translator = $t->getTranslator(); |
||
| 198 | $t->data['attributes'] = $attributes; |
||
| 199 | $t->data['checked'] = $state['consent:checked']; |
||
| 200 | $t->data['stateId'] = $stateId; |
||
| 201 | |||
| 202 | $t->data['srcName'] = is_array($srcName) ? $translator->getPreferredTranslation($srcName) : $srcName; |
||
|
|
|||
| 203 | $t->data['dstName'] = is_array($dstName) ? $translator->getPreferredTranslation($dstName) : $dstName; |
||
| 204 | |||
| 205 | if (array_key_exists('descr_purpose', $state['Destination'])) { |
||
| 206 | $t->data['dstDesc'] = $translator->getPreferredTranslation( |
||
| 207 | Utils\Arrays::arrayize( |
||
| 208 | $state['Destination']['descr_purpose'], |
||
| 209 | 'en' |
||
| 210 | ) |
||
| 211 | ); |
||
| 212 | } |
||
| 213 | |||
| 214 | // Fetch privacy policy |
||
| 215 | if ( |
||
| 216 | array_key_exists('UIInfo', $state['Destination']) && |
||
| 217 | array_key_exists('PrivacyStatementURL', $state['Destination']['UIInfo']) && |
||
| 218 | (!empty($state['Destination']['UIInfo']['PrivacyStatementURL'])) |
||
| 219 | ) { |
||
| 220 | $privacypolicy = reset($state['Destination']['UIInfo']['PrivacyStatementURL']); |
||
| 221 | } elseif ( |
||
| 222 | array_key_exists('UIInfo', $state['Source']) && |
||
| 223 | array_key_exists('PrivacyStatementURL', $state['Source']['UIInfo']) && |
||
| 224 | (!empty($state['Source']['UIInfo']['PrivacyStatementURL'])) |
||
| 225 | ) { |
||
| 226 | $privacypolicy = reset($state['Source']['UIInfo']['PrivacyStatementURL']); |
||
| 227 | } else { |
||
| 228 | $privacypolicy = false; |
||
| 229 | } |
||
| 230 | if ($privacypolicy !== false) { |
||
| 231 | $privacypolicy = str_replace( |
||
| 232 | '%SPENTITYID%', |
||
| 233 | urlencode($spentityid), |
||
| 234 | $privacypolicy |
||
| 235 | ); |
||
| 236 | } |
||
| 237 | $t->data['sppp'] = $privacypolicy; |
||
| 238 | |||
| 239 | // Set focus element |
||
| 240 | switch ($state['consent:focus']) { |
||
| 241 | case 'yes': |
||
| 242 | $t->data['autofocus'] = 'yesbutton'; |
||
| 243 | break; |
||
| 244 | case 'no': |
||
| 245 | $t->data['autofocus'] = 'nobutton'; |
||
| 246 | break; |
||
| 247 | case null: |
||
| 248 | default: |
||
| 249 | break; |
||
| 250 | } |
||
| 251 | |||
| 252 | $t->data['usestorage'] = array_key_exists('consent:store', $state); |
||
| 253 | |||
| 254 | return $t; |
||
| 255 | } |
||
| 350 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.