Passed
Pull Request — master (#4)
by Stephen
02:30
created

AutocompleteCityAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseResponse() 0 14 2
1
<?php
2
3
namespace Sfneal\GooglePlaces\Actions;
4
5
use Sfneal\GooglePlaces\Actions\Abstracts\PlacesSearchAction;
6
7
class AutocompleteCityAction extends PlacesSearchAction
8
{
9
    /**
10
     * Parse the Google Places API response and return an array.
11
     *
12
     * @param $response
13
     * @return array
14
     */
15
    public function parseResponse($response): array
16
    {
17
        // Parse predictions
18
        $i = 0;
19
        foreach ($response['predictions'] as $res) {
20
            $this->results[$i]['id'] = $res['description'];
21
            $this->results[$i]['text'] = $res['description'];
22
            $this->results[$i]['place_id'] = $res['place_id'];
23
            $i++;
24
        }
25
26
        return [
27
            'total_count' => count($this->results),
28
            'items' => $this->results,
29
        ];
30
    }
31
}
32