| Conditions | 4 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 27 |
| 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 |
||
| 79 | protected function handleActorImportedFromUDB2(ActorImportedFromUDB2 $actorImportedFromUDB2) |
||
| 80 | { |
||
| 81 | $actor = ActorItemFactory::createActorFromCdbXml( |
||
| 82 | $actorImportedFromUDB2->getCdbXmlNamespaceUri(), |
||
| 83 | $actorImportedFromUDB2->getCdbXml() |
||
| 84 | ); |
||
| 85 | |||
| 86 | $contactInfo = $actor->getContactInfo(); |
||
| 87 | |||
| 88 | // Do nothing if no contact info is found. |
||
| 89 | if (!$contactInfo) { |
||
| 90 | return; |
||
| 91 | } |
||
| 92 | |||
| 93 | // Get all physical locations from the list of addresses. |
||
| 94 | $addresses = array_map( |
||
| 95 | function (CultureFeed_Cdb_Data_Address $address) { |
||
| 96 | return $address->getPhysicalAddress(); |
||
| 97 | }, |
||
| 98 | $contactInfo->getAddresses() |
||
| 99 | ); |
||
| 100 | |||
| 101 | // Filter out addresses without physical location. |
||
| 102 | $addresses = array_filter($addresses); |
||
| 103 | |||
| 104 | // Do nothing if no address is found. |
||
| 105 | if (empty($addresses)) { |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | /* @var \CultureFeed_Cdb_Data_Address_PhysicalAddress $cdbAddress */ |
||
| 110 | $cdbAddress = $addresses[0]; |
||
| 111 | |||
| 112 | try { |
||
| 113 | // Convert the cdbxml address to a udb3 address. |
||
| 114 | $address = $this->addressFactory->fromCdbAddress($cdbAddress); |
||
| 115 | } catch (\InvalidArgumentException $e) { |
||
| 116 | // If conversion failed, log an error and do nothing. |
||
| 117 | $this->logger->error( |
||
| 118 | 'Could not convert a cdbxml address to a udb3 address for geocoding.', |
||
| 119 | [ |
||
| 120 | 'placeId' => $actorImportedFromUDB2->getActorId(), |
||
| 121 | 'error' => $e->getMessage(), |
||
| 122 | ] |
||
| 123 | ); |
||
| 124 | return; |
||
| 125 | } |
||
| 126 | |||
| 127 | // We don't know if the address has actually been updated because |
||
| 128 | // ActorImportedFromUDB2 is too coarse, but if we use the cached |
||
| 129 | // geocoding service we won't be wasting much resources when using |
||
| 130 | // a naive approach like this. |
||
| 131 | $command = new UpdateGeoCoordinatesFromAddress( |
||
| 132 | $actorImportedFromUDB2->getActorId(), |
||
| 133 | $address |
||
| 134 | ); |
||
| 135 | |||
| 136 | $this->commandBus->dispatch($command); |
||
| 137 | } |
||
| 138 | } |
||
| 139 |