Passed
Push — master ( 25ef95...88bd2b )
by Stephen
02:06
created

AutocompleteCityAction::parseResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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