Geolocation::geolocate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
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