Skip to content

Commit 030f978

Browse files
committed
Merge branch 'hotfix/Util'
2 parents 76f70dd + f1f6146 commit 030f978

File tree

3 files changed

+63
-23
lines changed

3 files changed

+63
-23
lines changed

.scrutinizer.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
build:
2+
nodes:
3+
coverage:
4+
tests:
5+
override:
6+
- command: vendor/bin/phpunit --coverage-clover=clover.xml
7+
coverage:
8+
file: clover.xml
9+
format: clover
10+
tools:
11+
php_code_sniffer:
12+
config:
13+
standard: PSR2

src/Api/Places.php

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
namespace Biscolab\GoogleMaps\Api;
1212

1313
use Biscolab\GoogleMaps\Abstracts\Api;
14-
use Biscolab\GoogleMaps\Config\Util;
1514
use Biscolab\GoogleMaps\Enum\PlaceServicesEndpoints;
1615
use Biscolab\GoogleMaps\Exception\InvalidArgumentException;
1716
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields;
1817
use Biscolab\GoogleMaps\Fields\GoogleMapsResultFields;
1918
use Biscolab\GoogleMaps\Http\GoogleMapsResultsCollection;
2019
use Biscolab\GoogleMaps\Http\Result\PlaceResultsCollection;
2120
use Biscolab\GoogleMaps\Object\Location;
21+
use Biscolab\GoogleMaps\Utils\Config;
2222
use Biscolab\GoogleMaps\Values\PlaceInputTypeValues;
2323
use Biscolab\GoogleMaps\Values\RankByValues;
2424

@@ -134,29 +134,15 @@ public function findPlaceByPhoneNumber(
134134
*
135135
* @return GoogleMapsResultsCollection
136136
*/
137-
public function findNearbyPlaceByRadius(Location $location, int $radius, ?array $params = []): GoogleMapsResultsCollection
138-
{
139-
140-
$params = array_merge($params, [
141-
GoogleMapsRequestFields::LOCATION => $location,
142-
GoogleMapsRequestFields::RADIUS => $radius
143-
]);
144-
145-
return $this->findNearbyPlace($params);
146-
}
147-
148-
/**
149-
* @param Location $location
150-
* @param array $params
151-
*
152-
* @return GoogleMapsResultsCollection
153-
*/
154-
public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection
155-
{
137+
public function findNearbyPlaceByRadius(
138+
Location $location,
139+
int $radius,
140+
?array $params = []
141+
): GoogleMapsResultsCollection {
156142

157143
$params = array_merge($params, [
158144
GoogleMapsRequestFields::LOCATION => $location,
159-
GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE
145+
GoogleMapsRequestFields::RADIUS => $radius
160146
]);
161147

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

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

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

202+
/**
203+
* @param Location $location
204+
* @param array $params
205+
*
206+
* @return GoogleMapsResultsCollection
207+
*/
208+
public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection
209+
{
210+
211+
$params = array_merge($params, [
212+
GoogleMapsRequestFields::LOCATION => $location,
213+
GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE
214+
]);
215+
216+
return $this->findNearbyPlace($params);
217+
}
218+
216219
/**
217220
* Nearby Search requests
218221
*

src/Utils/Config.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2019 - present
4+
* Google Maps PHP - Config.php
5+
* author: Roberto Belotti - [email protected]
6+
* web : robertobelotti.com, github.com/biscolab
7+
* Initial version created on: 10/9/2019
8+
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
9+
*/
10+
11+
12+
namespace Biscolab\GoogleMaps\Utils;
13+
14+
/**
15+
* Class Config
16+
* @package Biscolab\GoogleMaps\Utils
17+
*/
18+
class Config
19+
{
20+
/**
21+
* @var int
22+
*/
23+
const MAX_PLACE_RADIUS_VALUE = 50000;
24+
}

0 commit comments

Comments
 (0)