Skip to content

Commit 5cbd114

Browse files
committed
Added boolean param for using qualified query instead of regular query
1 parent b2b19a5 commit 5cbd114

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

src/Provider/Here/Here.php

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ final class Here extends AbstractHttpProvider
4141
*/
4242
public const REVERSE_ENDPOINT_URL = 'https://revgeocode.search.hereapi.com/v1/revgeocode';
4343

44-
/**
45-
* @var string[]
46-
*/
47-
public const GEOCODE_QUALIFIED_QUERY_PARAMS = [
48-
'houseNumber',
49-
'street',
50-
'city',
51-
'district',
52-
'county',
53-
'state',
54-
'country',
55-
'postalCode',
56-
];
57-
5844
/**
5945
* @var string[]
6046
*/
@@ -153,23 +139,10 @@ public function geocodeQuery(GeocodeQuery $query): Collection
153139

154140
$queryParams = $this->withApiCredentials([]);
155141

156-
if ($queryString = $query->getText()) {
157-
$queryParams['q'] = $queryString;
158-
}
159-
160-
foreach ($this::GEOCODE_QUALIFIED_QUERY_PARAMS as $param) {
161-
if ($data = $query->getData($param)) {
162-
if (!\array_key_exists('qq', $queryParams)) {
163-
$queryParams['qq'] = '';
164-
} else {
165-
$queryParams['qq'] .= ';';
166-
}
167-
$queryParams['qq'] .= $param.'='.$data;
168-
}
169-
}
170-
171-
if (!\array_key_exists('q', $queryParams) && !\array_key_exists('qq', $queryParams)) {
172-
throw new InvalidArgument('Query q or Qualified Query qq is required');
142+
if (true === $query->getData('qq')) {
143+
$queryParams['qq'] = $query->getText();
144+
} else {
145+
$queryParams['q'] = $query->getText();
173146
}
174147

175148
if ($center = $query->getData('centerOn')) {
@@ -306,12 +279,12 @@ private function executeQuery(string $url, int $limit): Collection
306279
$builder->setTimezone($location['timeZone']['name'] ?? null);
307280

308281
$additionalData = [
309-
'countryInfo' => $location['countryInfo'] ?? null,
310-
'parsing' => $location['parsing'] ?? null,
311-
'streetInfo' => $location['streetInfo'] ?? null,
312-
'postalCodeDetails' => $location['postalCodeDetails'] ?? null,
313-
'mapReferences' => $location['mapReferences'] ?? null,
314-
'navigationAttributes' => $location['navigationAttributes'] ?? null,
282+
['key' => 'countryInfo', 'value' => $location['countryInfo'] ?? null],
283+
['key' => 'parsing', 'value' => $location['parsing'] ?? null],
284+
['key' => 'streetInfo', 'value' => $location['streetInfo'] ?? null],
285+
['key' => 'postalCodeDetails', 'value' => $location['postalCodeDetails'] ?? null],
286+
['key' => 'mapReferences', 'value' => $location['mapReferences'] ?? null],
287+
['key' => 'navigationAttributes', 'value' => $location['navigationAttributes'] ?? null],
315288
];
316289

317290
/** @var HereAddress $address */

0 commit comments

Comments
 (0)