Issues (9)

src/Services/Roads.php (1 issue)

Severity
1
<?php
2
3
namespace kalanis\google_maps\Services;
4
5
6
use kalanis\google_maps\ServiceException;
7
use Psr\Http\Message\RequestInterface;
8
9
10
/**
11
 * Roads Service
12
 *
13
 * @see https://developers.google.com/maps/documentation/roads
14
 */
15
class Roads extends AbstractService
16
{
17
    /**
18
     * Roads lookup
19
     * @param array<int, float[]>|string|null $path
20
     * @param array<string, string|int|float> $params Query parameters
21
     * @throws ServiceException
22
     * @return RequestInterface
23
     */
24 3
    public function snapToRoads(array|string|null $path = null, array $params = []): RequestInterface
25
    {
26 3
        if (is_array($path)) {
27 1
            $positions = [];
28 1
            foreach ($path as $key => $eachPathArray) {
29 1
                $positions[] = implode(',', $eachPathArray);
30
            }
31 1
            $params['path'] = implode('|', $positions);
32 2
        } elseif (is_string($path)) {
0 ignored issues
show
The condition is_string($path) is always false.
Loading history...
33 1
            $params['path'] = $path;
34
        } else {
35 1
            throw new ServiceException('Unknown path format. Pass array of arrays of floats or the string itself.');
36
        }
37
38 2
        if (isset($params['interpolate'])) {
39 2
            if ($params['interpolate']) {
40 1
                $params['interpolate'] = 'true';
41
            } else {
42 1
                unset($params['interpolate']);
43
            }
44
        }
45
46 2
        return $this->getWithDefaults(
47 2
            'https://roads.googleapis.com/v1/snapToRoads',
48 2
            $this->queryParams($params)
49 2
        );
50
    }
51
}
52