Autocomplete::complete()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.439
cc 6
eloc 16
nc 6
nop 2
1
<?php
2
3
/**
4
 * This file is a part of nekland places api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\PlacesApi\Api;
13
14
15
use Nekland\BaseApi\Api\AbstractApi;
16
use Nekland\BaseApi\Exception\AuthenticationException;
17
use Nekland\BaseApi\Exception\QuotaLimitException;
18
19
class Autocomplete extends AbstractApi
20
{
21
    const URL = 'autocomplete/json';
22
23
    public function complete($input, array $other = [])
24
    {
25
        $body = array_merge(['input' => $input], $other);
26
27
        $result = $this->get(self::URL, $body);
28
29
        switch($result['status']) {
30
            case 'OK':
31
                return $result['predictions'];
32
33
            case 'ZERO_RESULTS':
34
                return [];
35
36
            case 'OVER_QUERY_LIMIT':
37
                throw new QuotaLimitException();
38
39
            case 'REQUEST_DENIED':
40
                throw new AuthenticationException();
41
42
            case 'INVALID_REQUEST':
43
                throw new \InvalidArgumentException('The input is not correct for autocomplete.');
44
45
            default:
46
                throw new \RuntimeException('This case is not supported, please report these to NeklandPlacesApi.');
47
        }
48
    }
49
}
50