| Conditions | 4 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 27 |
| 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 |
||
| 116 | private function handleActorImportedFromUDB2(ActorImportedFromUDB2 $actorImportedFromUDB2) |
||
| 117 | { |
||
| 118 | $actor = ActorItemFactory::createActorFromCdbXml( |
||
| 119 | $actorImportedFromUDB2->getCdbXmlNamespaceUri(), |
||
| 120 | $actorImportedFromUDB2->getCdbXml() |
||
| 121 | ); |
||
| 122 | |||
| 123 | $contactInfo = $actor->getContactInfo(); |
||
| 124 | |||
| 125 | // Do nothing if no contact info is found. |
||
| 126 | if (!$contactInfo) { |
||
| 127 | return; |
||
| 128 | } |
||
| 129 | |||
| 130 | // Get all physical locations from the list of addresses. |
||
| 131 | $addresses = array_map( |
||
| 132 | function (CultureFeed_Cdb_Data_Address $address) { |
||
| 133 | return $address->getPhysicalAddress(); |
||
| 134 | }, |
||
| 135 | $contactInfo->getAddresses() |
||
| 136 | ); |
||
| 137 | |||
| 138 | // Filter out addresses without physical location. |
||
| 139 | $addresses = array_filter($addresses); |
||
| 140 | |||
| 141 | // Do nothing if no address is found. |
||
| 142 | if (empty($addresses)) { |
||
| 143 | return; |
||
| 144 | } |
||
| 145 | |||
| 146 | /* @var \CultureFeed_Cdb_Data_Address_PhysicalAddress $cdbAddress */ |
||
| 147 | $cdbAddress = $addresses[0]; |
||
| 148 | |||
| 149 | try { |
||
| 150 | // Convert the cdbxml address to a udb3 address. |
||
| 151 | $address = $this->addressFactory->fromCdbAddress($cdbAddress); |
||
| 152 | } catch (\InvalidArgumentException $e) { |
||
| 153 | // If conversion failed, log an error and do nothing. |
||
| 154 | $this->logger->error( |
||
| 155 | 'Could not convert a cdbxml address to a udb3 address for geocoding.', |
||
| 156 | [ |
||
| 157 | 'placeId' => $actorImportedFromUDB2->getActorId(), |
||
| 158 | 'error' => $e->getMessage(), |
||
| 159 | ] |
||
| 160 | ); |
||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | // We don't know if the address has actually been updated because |
||
| 165 | // ActorImportedFromUDB2 is too coarse, but if we use the cached |
||
| 166 | // geocoding service we won't be wasting much resources when using |
||
| 167 | // a naive approach like this. |
||
| 168 | $command = new UpdateGeoCoordinatesFromAddress( |
||
| 169 | $actorImportedFromUDB2->getActorId(), |
||
| 170 | $address |
||
| 171 | ); |
||
| 172 | |||
| 173 | $this->commandBus->dispatch($command); |
||
| 174 | } |
||
| 175 | } |
||
| 176 |