Skip to content

Commit 81a6bda

Browse files
dkemperNyholm
authored andcommitted
GoogleMaps: Channel parameter (#789)
* added channel parameter, used class methods for tests, strictly docblocks, fix parameter problem for name parameter * removed .idea xml * changed docblock * cs fixes * cs fixes
1 parent 89afede commit 81a6bda

File tree

3 files changed

+90
-50
lines changed

3 files changed

+90
-50
lines changed

src/Provider/GoogleMaps/GoogleMaps.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ final class GoogleMaps extends AbstractHttpProvider implements Provider
6161
*/
6262
private $privateKey;
6363

64+
/**
65+
* @var string|null
66+
*/
67+
private $channel;
68+
6469
/**
6570
* Google Maps for Business
6671
* https://developers.google.com/maps/documentation/business/.
@@ -70,14 +75,16 @@ final class GoogleMaps extends AbstractHttpProvider implements Provider
7075
* @param string $privateKey Your Private Key (optional)
7176
* @param string $region Region biasing (optional)
7277
* @param string $apiKey Google Geocoding API key (optional)
78+
* @param string $channel Google Channel parameter (optional)
7379
*
7480
* @return GoogleMaps
7581
*/
76-
public static function business(HttpClient $client, string $clientId, string $privateKey = null, string $region = null, string $apiKey = null)
82+
public static function business(HttpClient $client, string $clientId, string $privateKey = null, string $region = null, string $apiKey = null, string $channel = null)
7783
{
7884
$provider = new self($client, $region, $apiKey);
7985
$provider->clientId = $clientId;
8086
$provider->privateKey = $privateKey;
87+
$provider->channel = $channel;
8188

8289
return $provider;
8390
}
@@ -141,7 +148,7 @@ public function getName(): string
141148
*
142149
* @return string query with extra params
143150
*/
144-
private function buildQuery(string $url, string $locale = null, string $region = null)
151+
private function buildQuery(string $url, string $locale = null, string $region = null): string
145152
{
146153
if (null !== $locale) {
147154
$url = sprintf('%s&language=%s', $url, $locale);
@@ -158,6 +165,10 @@ private function buildQuery(string $url, string $locale = null, string $region =
158165
if (null !== $this->clientId) {
159166
$url = sprintf('%s&client=%s', $url, $this->clientId);
160167

168+
if (null !== $this->channel) {
169+
$url = sprintf('%s&channel=%s', $url, $this->channel);
170+
}
171+
161172
if (null !== $this->privateKey) {
162173
$url = $this->signQuery($url);
163174
}

src/Provider/GoogleMaps/Model/GoogleAddress.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ final class GoogleAddress extends Address
116116
*
117117
* @return GoogleAddress
118118
*/
119-
public function withId(string $id = null)
119+
public function withId(string $id = null): GoogleAddress
120120
{
121121
$new = clone $this;
122122
$new->id = $id;
@@ -139,7 +139,7 @@ public function getId()
139139
*
140140
* @return GoogleAddress
141141
*/
142-
public function withLocationType(string $locationType = null)
142+
public function withLocationType(string $locationType = null): GoogleAddress
143143
{
144144
$new = clone $this;
145145
$new->locationType = $locationType;
@@ -168,7 +168,7 @@ public function getResultType(): array
168168
*
169169
* @return GoogleAddress
170170
*/
171-
public function withResultType(array $resultType)
171+
public function withResultType(array $resultType): GoogleAddress
172172
{
173173
$new = clone $this;
174174
$new->resultType = $resultType;
@@ -189,7 +189,7 @@ public function getFormattedAddress()
189189
*
190190
* @return GoogleAddress
191191
*/
192-
public function withFormattedAddress(string $formattedAddress = null)
192+
public function withFormattedAddress(string $formattedAddress = null): GoogleAddress
193193
{
194194
$new = clone $this;
195195
$new->formattedAddress = $formattedAddress;
@@ -210,7 +210,7 @@ public function getAirport()
210210
*
211211
* @return GoogleAddress
212212
*/
213-
public function withAirport(string $airport = null)
213+
public function withAirport(string $airport = null): GoogleAddress
214214
{
215215
$new = clone $this;
216216
$new->airport = $airport;
@@ -231,7 +231,7 @@ public function getColloquialArea()
231231
*
232232
* @return GoogleAddress
233233
*/
234-
public function withColloquialArea(string $colloquialArea = null)
234+
public function withColloquialArea(string $colloquialArea = null): GoogleAddress
235235
{
236236
$new = clone $this;
237237
$new->colloquialArea = $colloquialArea;
@@ -252,7 +252,7 @@ public function getIntersection()
252252
*
253253
* @return GoogleAddress
254254
*/
255-
public function withIntersection(string $intersection = null)
255+
public function withIntersection(string $intersection = null): GoogleAddress
256256
{
257257
$new = clone $this;
258258
$new->intersection = $intersection;
@@ -273,7 +273,7 @@ public function getNaturalFeature()
273273
*
274274
* @return GoogleAddress
275275
*/
276-
public function withNaturalFeature(string $naturalFeature = null)
276+
public function withNaturalFeature(string $naturalFeature = null): GoogleAddress
277277
{
278278
$new = clone $this;
279279
$new->naturalFeature = $naturalFeature;
@@ -294,7 +294,7 @@ public function getNeighborhood()
294294
*
295295
* @return GoogleAddress
296296
*/
297-
public function withNeighborhood(string $neighborhood = null)
297+
public function withNeighborhood(string $neighborhood = null): GoogleAddress
298298
{
299299
$new = clone $this;
300300
$new->neighborhood = $neighborhood;
@@ -315,7 +315,7 @@ public function getPark()
315315
*
316316
* @return GoogleAddress
317317
*/
318-
public function withPark(string $park = null)
318+
public function withPark(string $park = null): GoogleAddress
319319
{
320320
$new = clone $this;
321321
$new->park = $park;
@@ -357,7 +357,7 @@ public function getPolitical()
357357
*
358358
* @return GoogleAddress
359359
*/
360-
public function withPolitical(string $political = null)
360+
public function withPolitical(string $political = null): GoogleAddress
361361
{
362362
$new = clone $this;
363363
$new->political = $political;
@@ -374,11 +374,11 @@ public function getPremise()
374374
}
375375

376376
/**
377-
* @param null $premise
377+
* @param string $premise
378378
*
379379
* @return GoogleAddress
380380
*/
381-
public function withPremise(string $premise = null)
381+
public function withPremise(string $premise = null): GoogleAddress
382382
{
383383
$new = clone $this;
384384
$new->premise = $premise;
@@ -399,7 +399,7 @@ public function getStreetAddress()
399399
*
400400
* @return GoogleAddress
401401
*/
402-
public function withStreetAddress(string $streetAddress = null)
402+
public function withStreetAddress(string $streetAddress = null): GoogleAddress
403403
{
404404
$new = clone $this;
405405
$new->streetAddress = $streetAddress;
@@ -420,7 +420,7 @@ public function getSubpremise()
420420
*
421421
* @return GoogleAddress
422422
*/
423-
public function withSubpremise(string $subpremise = null)
423+
public function withSubpremise(string $subpremise = null): GoogleAddress
424424
{
425425
$new = clone $this;
426426
$new->subpremise = $subpremise;
@@ -441,7 +441,7 @@ public function getWard()
441441
*
442442
* @return GoogleAddress
443443
*/
444-
public function withWard(string $ward = null)
444+
public function withWard(string $ward = null): GoogleAddress
445445
{
446446
$new = clone $this;
447447
$new->ward = $ward;
@@ -462,7 +462,7 @@ public function getEstablishment()
462462
*
463463
* @return GoogleAddress
464464
*/
465-
public function withEstablishment(string $establishment = null)
465+
public function withEstablishment(string $establishment = null): GoogleAddress
466466
{
467467
$new = clone $this;
468468
$new->establishment = $establishment;
@@ -473,7 +473,7 @@ public function withEstablishment(string $establishment = null)
473473
/**
474474
* @return AdminLevelCollection
475475
*/
476-
public function getSubLocalityLevels()
476+
public function getSubLocalityLevels(): AdminLevelCollection
477477
{
478478
return $this->subLocalityLevels;
479479
}
@@ -483,15 +483,15 @@ public function getSubLocalityLevels()
483483
*
484484
* @return $this
485485
*/
486-
public function withSubLocalityLevels(array $subLocalityLevel)
486+
public function withSubLocalityLevels(array $subLocalityLevel): GoogleAddress
487487
{
488488
$subLocalityLevels = [];
489489
foreach ($subLocalityLevel as $level) {
490490
if (empty($level['level'])) {
491491
continue;
492492
}
493493

494-
$name = $level['name'] ?? $level['code'] ?? null;
494+
$name = $level['name'] ?? $level['code'] ?? '';
495495
if (empty($name)) {
496496
continue;
497497
}

0 commit comments

Comments
 (0)