Autocomplete   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B complete() 0 26 6
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