| Conditions | 13 |
| Paths | 50 |
| Total Lines | 114 |
| Code Lines | 72 |
| 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 |
||
| 234 | public function process(array &$state): void |
||
| 235 | { |
||
| 236 | Assert::keyExists($state, 'UserID'); |
||
| 237 | Assert::keyExists($state, 'Destination'); |
||
| 238 | Assert::keyExists($state['Destination'], 'entityid'); |
||
| 239 | Assert::keyExists($state['Destination'], 'metadata-set'); |
||
| 240 | Assert::keyExists($state['Source'], 'entityid'); |
||
| 241 | Assert::keyExists($state['Source'], 'metadata-set'); |
||
| 242 | |||
| 243 | $spEntityId = $state['Destination']['entityid']; |
||
| 244 | $idpEntityId = $state['Source']['entityid']; |
||
| 245 | |||
| 246 | $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); |
||
| 247 | |||
| 248 | /** |
||
| 249 | * If the consent module is active on a bridge $state['saml:sp:IdP'] |
||
| 250 | * will contain an entry id for the remote IdP. If not, then the |
||
| 251 | * consent module is active on a local IdP and nothing needs to be |
||
| 252 | * done. |
||
| 253 | */ |
||
| 254 | if (isset($state['saml:sp:IdP'])) { |
||
| 255 | $idpEntityId = $state['saml:sp:IdP']; |
||
| 256 | $idpmeta = $metadata->getMetaData($idpEntityId, 'saml20-idp-remote'); |
||
| 257 | $state['Source'] = $idpmeta; |
||
| 258 | } |
||
| 259 | |||
| 260 | $statsData = ['spEntityID' => $spEntityId]; |
||
| 261 | |||
| 262 | // Do not use consent if disabled |
||
| 263 | if ( |
||
| 264 | isset($state['Source']['consent.disable']) && |
||
| 265 | self::checkDisable($state['Source']['consent.disable'], $spEntityId) |
||
| 266 | ) { |
||
| 267 | Logger::debug('Consent: Consent disabled for entity ' . $spEntityId . ' with IdP ' . $idpEntityId); |
||
| 268 | Stats::log('consent:disabled', $statsData); |
||
| 269 | return; |
||
| 270 | } |
||
| 271 | if ( |
||
| 272 | isset($state['Destination']['consent.disable']) && |
||
| 273 | self::checkDisable($state['Destination']['consent.disable'], $idpEntityId) |
||
| 274 | ) { |
||
| 275 | Logger::debug('Consent: Consent disabled for entity ' . $spEntityId . ' with IdP ' . $idpEntityId); |
||
| 276 | Stats::log('consent:disabled', $statsData); |
||
| 277 | return; |
||
| 278 | } |
||
| 279 | |||
| 280 | if ($this->store !== null) { |
||
| 281 | $source = $state['Source']['metadata-set'] . '|' . $idpEntityId; |
||
| 282 | $destination = $state['Destination']['metadata-set'] . '|' . $spEntityId; |
||
| 283 | $attributes = $state['Attributes']; |
||
| 284 | |||
| 285 | // Remove attributes that do not require consent |
||
| 286 | foreach ($attributes as $attrkey => $attrval) { |
||
| 287 | if (in_array($attrkey, $this->noconsentattributes, true)) { |
||
| 288 | unset($attributes[$attrkey]); |
||
| 289 | } |
||
| 290 | } |
||
| 291 | |||
| 292 | Logger::debug('Consent: userid: ' . $state['UserID']); |
||
| 293 | Logger::debug('Consent: source: ' . $source); |
||
| 294 | Logger::debug('Consent: destination: ' . $destination); |
||
| 295 | |||
| 296 | $userId = self::getHashedUserID($state['UserID'], $source); |
||
| 297 | $targetedId = self::getTargetedID($state['UserID'], $source, $destination); |
||
| 298 | $attributeSet = self::getAttributeHash($attributes, $this->includeValues); |
||
| 299 | |||
| 300 | Logger::debug( |
||
| 301 | 'Consent: hasConsent() [' . $userId . '|' . $targetedId . '|' . $attributeSet . ']' |
||
| 302 | ); |
||
| 303 | |||
| 304 | try { |
||
| 305 | if ($this->store->hasConsent($userId, $targetedId, $attributeSet)) { |
||
| 306 | // Consent already given |
||
| 307 | Logger::stats('consent found'); |
||
| 308 | Stats::log('consent:found', $statsData); |
||
| 309 | return; |
||
| 310 | } |
||
| 311 | |||
| 312 | Logger::stats('consent notfound'); |
||
| 313 | Stats::log('consent:notfound', $statsData); |
||
| 314 | |||
| 315 | $state['consent:store'] = $this->store; |
||
| 316 | $state['consent:store.userId'] = $userId; |
||
| 317 | $state['consent:store.destination'] = $targetedId; |
||
| 318 | $state['consent:store.attributeSet'] = $attributeSet; |
||
| 319 | } catch (\Exception $e) { |
||
| 320 | Logger::error('Consent: Error reading from storage: ' . $e->getMessage()); |
||
| 321 | Logger::stats('Consent failed'); |
||
| 322 | Stats::log('consent:failed', $statsData); |
||
| 323 | } |
||
| 324 | } else { |
||
| 325 | Logger::stats('consent nostorage'); |
||
| 326 | Stats::log('consent:nostorage', $statsData); |
||
| 327 | } |
||
| 328 | |||
| 329 | $state['consent:focus'] = $this->focus; |
||
| 330 | $state['consent:checked'] = $this->checked; |
||
| 331 | $state['consent:hiddenAttributes'] = $this->hiddenAttributes; |
||
| 332 | $state['consent:noconsentattributes'] = $this->noconsentattributes; |
||
| 333 | $state['consent:showNoConsentAboutService'] = $this->showNoConsentAboutService; |
||
| 334 | |||
| 335 | // user interaction necessary. Throw exception on isPassive request |
||
| 336 | if (isset($state['isPassive']) && $state['isPassive'] === true) { |
||
| 337 | Stats::log('consent:nopassive', $statsData); |
||
| 338 | throw new Module\saml\Error\NoPassive( |
||
| 339 | \SAML2\Constants::STATUS_REQUESTER, |
||
| 340 | 'Unable to give consent on passive request.' |
||
| 341 | ); |
||
| 342 | } |
||
| 343 | |||
| 344 | // Save state and redirect |
||
| 345 | $id = \SimpleSAML\Auth\State::saveState($state, 'consent:request'); |
||
| 346 | $url = Module::getModuleURL('consent/getconsent.php'); |
||
| 347 | Utils\HTTP::redirectTrustedURL($url, ['StateId' => $id]); |
||
| 348 | } |
||
| 407 |