| Conditions | 9 |
| Paths | 10 |
| Total Lines | 60 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 applyAttributeReleasePolicies(ConsentList $consentList, AttributeSetInterface $attributeSet) |
||
| 60 | { |
||
| 61 | $entityIds = $consentList->map(function (Consent $consent) { |
||
| 62 | return $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); |
||
| 63 | }); |
||
| 64 | |||
| 65 | $mappedAttributes = []; |
||
| 66 | foreach ($attributeSet as $attribute) { |
||
| 67 | $mace = $attribute->getAttributeDefinition()->getUrnMace(); |
||
| 68 | $oid = $attribute->getAttributeDefinition()->getUrnOid(); |
||
| 69 | |||
| 70 | if ($mace !== null) { |
||
| 71 | $mappedAttributes[$mace] = $attribute->getValue(); |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($oid !== null) { |
||
| 75 | $mappedAttributes[$oid] = $attribute->getValue(); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | $data = [ |
||
| 80 | 'entityIds' => $entityIds, |
||
| 81 | 'attributes' => !empty($mappedAttributes) ? $mappedAttributes : new stdClass() |
||
| 82 | ]; |
||
| 83 | $response = $this->jsonApiClient->post($data, '/arp'); |
||
| 84 | |||
| 85 | $specifiedConsents = $consentList->map( |
||
| 86 | function (Consent $consent) use ($response) { |
||
| 87 | $entityId = $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); |
||
| 88 | |||
| 89 | if (!isset($response[$entityId])) { |
||
| 90 | throw new InvalidResponseException( |
||
| 91 | sprintf( |
||
| 92 | 'EntityID "%s" was not found in the ARP response (entityIDs: %s)', |
||
| 93 | $entityId, |
||
| 94 | join(', ', array_keys($response)) |
||
| 95 | ) |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | $attributes = []; |
||
| 100 | foreach ($response[$entityId] as $attributeName => $attributeValue) { |
||
| 101 | try { |
||
| 102 | $attributeDefinition = $this->attributeDictionary->getAttributeDefinitionByUrn($attributeName); |
||
| 103 | } catch (UnknownUrnException $exception) { |
||
| 104 | $attributeDefinition = new AttributeDefinition($attributeName, $attributeName, $attributeName); |
||
| 105 | } |
||
| 106 | |||
| 107 | $attribute = new Attribute($attributeDefinition, $attributeValue); |
||
| 108 | if (!in_array($attribute, $attributes)) { |
||
| 109 | $attributes[] = $attribute; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return SpecifiedConsent::specifies($consent, AttributeSetWithFallbacks::create($attributes)); |
||
| 114 | } |
||
| 115 | ); |
||
| 116 | |||
| 117 | return SpecifiedConsentList::createWith($specifiedConsents); |
||
| 118 | } |
||
| 119 | } |
||
| 120 |