Skip to content

Commit

Permalink
Merge branch 'hotfix/Util'
Browse files Browse the repository at this point in the history
  • Loading branch information
biscolab committed Sep 10, 2019
2 parents 76f70dd + f1f6146 commit 030f978
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
build:
nodes:
coverage:
tests:
override:
- command: vendor/bin/phpunit --coverage-clover=clover.xml
coverage:
file: clover.xml
format: clover
tools:
php_code_sniffer:
config:
standard: PSR2
49 changes: 26 additions & 23 deletions src/Api/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
namespace Biscolab\GoogleMaps\Api;

use Biscolab\GoogleMaps\Abstracts\Api;
use Biscolab\GoogleMaps\Config\Util;
use Biscolab\GoogleMaps\Enum\PlaceServicesEndpoints;
use Biscolab\GoogleMaps\Exception\InvalidArgumentException;
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
use Biscolab\GoogleMaps\Fields\GoogleMapsResultFields;
use Biscolab\GoogleMaps\Http\GoogleMapsResultsCollection;
use Biscolab\GoogleMaps\Http\Result\PlaceResultsCollection;
use Biscolab\GoogleMaps\Object\Location;
use Biscolab\GoogleMaps\Utils\Config;
use Biscolab\GoogleMaps\Values\PlaceInputTypeValues;
use Biscolab\GoogleMaps\Values\RankByValues;

Expand Down Expand Up @@ -134,29 +134,15 @@ public function findPlaceByPhoneNumber(
*
* @return GoogleMapsResultsCollection
*/
public function findNearbyPlaceByRadius(Location $location, int $radius, ?array $params = []): GoogleMapsResultsCollection
{

$params = array_merge($params, [
GoogleMapsRequestFields::LOCATION => $location,
GoogleMapsRequestFields::RADIUS => $radius
]);

return $this->findNearbyPlace($params);
}

/**
* @param Location $location
* @param array $params
*
* @return GoogleMapsResultsCollection
*/
public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection
{
public function findNearbyPlaceByRadius(
Location $location,
int $radius,
?array $params = []
): GoogleMapsResultsCollection {

$params = array_merge($params, [
GoogleMapsRequestFields::LOCATION => $location,
GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE
GoogleMapsRequestFields::RADIUS => $radius
]);

return $this->findNearbyPlace($params);
Expand Down Expand Up @@ -205,14 +191,31 @@ public function findNearbyPlace(array $params): GoogleMapsResultsCollection
throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' field is required');
}

if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Util::MAX_PLACE_RADIUS_VALUE) {
if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Config::MAX_PLACE_RADIUS_VALUE) {
// The maximum allowed radius is 50 000 meters.
throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Util::MAX_PLACE_RADIUS_VALUE);
throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Config::MAX_PLACE_RADIUS_VALUE);
}

return $this->makeApiCall($params, PlaceServicesEndpoints::NEARBYSEARCH);
}

/**
* @param Location $location
* @param array $params
*
* @return GoogleMapsResultsCollection
*/
public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection
{

$params = array_merge($params, [
GoogleMapsRequestFields::LOCATION => $location,
GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE
]);

return $this->findNearbyPlace($params);
}

/**
* Nearby Search requests
*
Expand Down
24 changes: 24 additions & 0 deletions src/Utils/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright (c) 2019 - present
* Google Maps PHP - Config.php
* author: Roberto Belotti - [email protected]
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 10/9/2019
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
*/


namespace Biscolab\GoogleMaps\Utils;

/**
* Class Config
* @package Biscolab\GoogleMaps\Utils
*/
class Config
{
/**
* @var int
*/
const MAX_PLACE_RADIUS_VALUE = 50000;
}

0 comments on commit 030f978

Please sign in to comment.