| Conditions | 8 |
| Paths | 5 |
| Total Lines | 55 |
| Code Lines | 32 |
| 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 |
||
| 57 | public function applyAttributeReleasePolicies(ConsentList $consentList, AttributeSetInterface $attributeSet) |
||
| 58 | { |
||
| 59 | $entityIds = $consentList->map(function (Consent $consent) { |
||
| 60 | return $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); |
||
| 61 | }); |
||
| 62 | |||
| 63 | $mappedAttributes = []; |
||
| 64 | foreach ($attributeSet as $attribute) { |
||
| 65 | $mace = $attribute->getAttributeDefinition()->getUrnMace(); |
||
| 66 | $oid = $attribute->getAttributeDefinition()->getUrnOid(); |
||
| 67 | |||
| 68 | if ($mace !== null) { |
||
| 69 | $mappedAttributes[$mace] = $attribute->getValue(); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($oid !== null) { |
||
| 73 | $mappedAttributes[$oid] = $attribute->getValue(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | $response = $this->jsonApiClient->post([ |
||
| 78 | 'entityIds' => $entityIds, |
||
| 79 | 'attributes' => !empty($mappedAttributes) ? $mappedAttributes : new stdClass() |
||
| 80 | ], '/arp'); |
||
| 81 | |||
| 82 | $specifiedConsents = $consentList->map( |
||
| 83 | function (Consent $consent) use ($response) { |
||
| 84 | $entityId = $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); |
||
| 85 | |||
| 86 | if (!isset($response[$entityId])) { |
||
| 87 | throw new InvalidResponseException( |
||
| 88 | sprintf( |
||
| 89 | 'EntityID "%s" was not found in the ARP response (entityIDs: %s)', |
||
| 90 | $entityId, |
||
| 91 | join(', ', array_keys($response)) |
||
| 92 | ) |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | $attributes = []; |
||
| 97 | foreach ($response[$entityId] as $attributeName => $attributeValue) { |
||
| 98 | $attributeDefinition = $this->attributeDictionary->findAttributeDefinitionByUrn($attributeName); |
||
| 99 | |||
| 100 | $attribute = new Attribute($attributeDefinition, $attributeValue); |
||
|
|
|||
| 101 | if (!in_array($attribute, $attributes)) { |
||
| 102 | $attributes[] = $attribute; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return SpecifiedConsent::specifies($consent, AttributeSetWithFallbacks::create($attributes)); |
||
| 107 | } |
||
| 108 | ); |
||
| 109 | |||
| 110 | return SpecifiedConsentList::createWith($specifiedConsents); |
||
| 111 | } |
||
| 112 | } |
||
| 113 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: