Issues (9)

src/Services/Geolocation.php (1 issue)

1
<?php
2
3
namespace kalanis\google_maps\Services;
4
5
6
use kalanis\google_maps\Remote\Body;
7
use kalanis\google_maps\ServiceException;
8
use Psr\Http\Message\RequestInterface;
9
10
11
/**
12
 * Directions Service
13
 *
14
 * @see     https://developers.google.com/maps/documentation/geolocation/
15
 * @see     https://developers.google.com/maps/documentation/geolocation/requests-geolocation
16
 */
17
class Geolocation extends AbstractService
18
{
19
    /**
20
     * Geolocate
21
     *
22
     * @param array<mixed> $bodyParams Body parameters
23
     * @throws ServiceException
24
     * @return RequestInterface
25
     */
26 1
    public function geolocate(array $bodyParams = []): RequestInterface
27
    {
28
        // Google API request body format
29 1
        $encoded = json_encode($bodyParams, JSON_UNESCAPED_SLASHES);
30 1
        if (false === $encoded) {
31
            // @codeCoverageIgnoreStart
32
            // to get this error you must have something really fishy in $bodyParams
33
            throw new ServiceException(json_last_error_msg());
34
        }
35
        // @codeCoverageIgnoreEnd
36
37 1
        return $this->getWithDefaults(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getWithDef...\Remote\Body($encoded)) returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\RequestInterface.
Loading history...
38 1
                'https://www.googleapis.com/geolocation/v1/geolocate',
39 1
                $this->queryParams([])
40 1
            )
41 1
            ->withMethod('POST')
42 1
            ->withBody(new Body($encoded));
43
    }
44
}
45