/** * @param Address $address */ public function validateRecipientAddress(Address $address) { try { $importCountry = $this->getImportCountry($address->getCountryCode()); } catch (InvalidArgumentException $e) { throw new ViolationException('Can not send a package to this country.'); } if (!array_key_exists($importCountry->getZone(), $this->get('zone_calculators'))) { throw new ViolationException('Can not send a package to this country.'); } }
/** * @param Address $address * @return ImportCountry|null */ protected function detectImportCountry(Address $address) { $countries = $this->get('import_countries'); $importCountry = null; if (array_key_exists($address->getCountryCode(), $countries)) { $importCountry = $countries[$address->getCountryCode()]; } return $importCountry; }