| Conditions | 10 |
| Paths | 10 |
| Total Lines | 73 |
| 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 |
||
| 64 | public function applyAttributeReleasePolicies(ConsentList $consentList, AttributeSetInterface $attributeSet) |
||
| 65 | { |
||
| 66 | $entityIds = $consentList->map(function (Consent $consent) { |
||
| 67 | return $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); |
||
| 68 | }); |
||
| 69 | |||
| 70 | $mappedAttributes = []; |
||
| 71 | foreach ($attributeSet as $attribute) { |
||
| 72 | $mace = $attribute->getAttributeDefinition()->getUrnMace(); |
||
| 73 | $oid = $attribute->getAttributeDefinition()->getUrnOid(); |
||
| 74 | |||
| 75 | if ($mace !== null) { |
||
| 76 | $mappedAttributes[$mace] = $attribute->getValue(); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($oid !== null) { |
||
| 80 | $mappedAttributes[$oid] = $attribute->getValue(); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $data = [ |
||
| 85 | 'entityIds' => $entityIds, |
||
| 86 | 'attributes' => !empty($mappedAttributes) ? $mappedAttributes : new stdClass(), |
||
| 87 | 'showSources' => true, |
||
| 88 | ]; |
||
| 89 | // Arp is applied for all entities |
||
| 90 | $response = $this->jsonApiClient->post($data, '/arp'); |
||
| 91 | |||
| 92 | $data = [ |
||
| 93 | 'entityIds' => $entityIds, |
||
| 94 | ]; |
||
| 95 | |||
| 96 | // Arp information is retrieved for all entities with arp enabled. |
||
| 97 | $arpResponse = $this->jsonApiClient->post($data, '/read-arp'); |
||
| 98 | |||
| 99 | $specifiedConsents = $consentList->map( |
||
| 100 | function (Consent $consent) use ($response, $arpResponse) { |
||
| 101 | $entityId = $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); |
||
| 102 | |||
| 103 | if (!isset($response[$entityId])) { |
||
| 104 | throw new InvalidResponseException( |
||
| 105 | sprintf( |
||
| 106 | 'EntityID "%s" was not found in the ARP response (entityIDs: %s)', |
||
| 107 | $entityId, |
||
| 108 | join(', ', array_keys($response)) |
||
| 109 | ) |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | |||
| 113 | $attributes = []; |
||
| 114 | foreach ($response[$entityId] as $attributeName => $attributeValue) { |
||
| 115 | try { |
||
| 116 | $attributeDefinition = $this->attributeDictionary->getAttributeDefinitionByUrn($attributeName); |
||
| 117 | } catch (UnknownUrnException $exception) { |
||
| 118 | $attributeDefinition = new AttributeDefinition($attributeName, $attributeName, $attributeName); |
||
| 119 | } |
||
| 120 | |||
| 121 | $attribute = new Attribute($attributeDefinition, $attributeValue); |
||
| 122 | if (!in_array($attribute, $attributes)) { |
||
| 123 | $attributes[] = $attribute; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | $arp = Arp::createWith([], null); |
||
| 127 | if (isset($arpResponse[$entityId])) { |
||
| 128 | $arp = Arp::createWith($arpResponse[$entityId], $this->attributeDictionary); |
||
| 129 | } |
||
| 130 | |||
| 131 | return SpecifiedConsent::specifies($consent, AttributeSetWithFallbacks::create($attributes), $arp); |
||
| 132 | } |
||
| 133 | ); |
||
| 134 | |||
| 135 | return SpecifiedConsentList::createWith($specifiedConsents); |
||
| 136 | } |
||
| 137 | } |
||
| 138 |