/**
  * Returns the location for given zip code
  *
  * @param string $zipCode
  *
  * @return Region
  *
  * @throws \EBT\GeoZipLocation\Exception\ResourceNotFoundException
  */
 public function getLocationForZip($zipCode)
 {
     $zipCode = $this->getSanitizeZipCode($zipCode);
     if (!$zipCode) {
         throw new TranslatorNotFoundException(sprintf('Zip code \'%s\' is not valid!', $zipCode));
     }
     /*
      * Polish zone/region could easily be computed by the first, second or the third digit(s) of the zip code. To
      * achieve that we will try to find one match on array map by exactly this order.
      */
     for ($substrSize = 5; $substrSize >= 1; $substrSize--) {
         $searchPattern = substr($zipCode, 0, $substrSize);
         if (isset($this->map[$searchPattern])) {
             $area = $this->repo_area->getById($this->map[$searchPattern][self::DATA_INDEX_AREA]);
             $zone = $this->repo_zone->getById($this->map[$searchPattern][self::DATA_INDEX_ZONE]);
             $region = $this->repo_region->getById($this->map[$searchPattern][self::DATA_INDEX_REGION]);
             $zone->setSubLocation($area);
             $region->setSubLocation($zone);
             return $region;
         }
     }
     /* If we reach this point then no region was found. throwing an error */
     throw new ResourceNotFoundException(sprintf('Unable to find a region for \'%s\' zipcode', $zipCode));
 }
 /**
  * testGetAll
  */
 public function testGetAll()
 {
     $r = new AreaRepository();
     $this->assertContainsOnlyInstancesOf('EBT\\GeoZipLocation\\Translator\\PL\\Location\\Area', $r->getAll());
 }