diff --git a/src/ProviderAndDumperAggregator.php b/src/ProviderAndDumperAggregator.php index 64c4a52..c07322b 100644 --- a/src/ProviderAndDumperAggregator.php +++ b/src/ProviderAndDumperAggregator.php @@ -9,19 +9,20 @@ * @license MIT License */ -use Geocoder\Dumper\GeoJson; +use ReflectionClass; +use Geocoder\Geocoder; use Geocoder\Dumper\Gpx; use Geocoder\Dumper\Kml; use Geocoder\Dumper\Wkb; use Geocoder\Dumper\Wkt; -use Geocoder\Geocoder; -use Geocoder\Laravel\Exceptions\InvalidDumperException; +use Geocoder\Query\Query; +use Illuminate\Support\Str; +use Geocoder\Dumper\GeoJson; use Geocoder\ProviderAggregator; use Geocoder\Query\GeocodeQuery; -use Geocoder\Query\Query; use Geocoder\Query\ReverseQuery; use Illuminate\Support\Collection; -use ReflectionClass; +use Geocoder\Laravel\Exceptions\InvalidDumperException; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) @@ -73,6 +74,7 @@ public function dump(string $dumper) : Collection "The dumper specified ('{$dumper}') is invalid. Valid dumpers ", "are: geojson, gpx, kml, wkb, wkt.", ]); + throw new InvalidDumperException($errorMessage); } @@ -87,7 +89,7 @@ public function dump(string $dumper) : Collection public function geocode(string $value) : self { - $cacheKey = str_slug(strtolower(urlencode($value))); + $cacheKey = Str::slug(strtolower(urlencode($value))); $this->results = $this->cacheRequest($cacheKey, [$value], "geocode"); return $this; @@ -156,7 +158,7 @@ public function registerProvidersFromConfig(Collection $providers) : self public function reverse(float $latitude, float $longitude) : self { - $cacheKey = str_slug(strtolower(urlencode("{$latitude}-{$longitude}"))); + $cacheKey = Str::slug(strtolower(urlencode("{$latitude}-{$longitude}"))); $this->results = $this->cacheRequest($cacheKey, [$latitude, $longitude], "reverse"); return $this; @@ -191,6 +193,7 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $ "value" => collect($this->aggregator->{$queryType}(...$queryElements)), ]; }); + $result = $this->preventCacheKeyHashCollision( $result, $hashedCacheKey, @@ -198,6 +201,7 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $ $queryElements, $queryType ); + $this->removeEmptyCacheEntry($result, $hashedCacheKey); return $result;