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

AutocompleteCityAction::parseResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
rs 9.9666
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