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

AutocompleteZipAction::parseResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 10
1
<?php
2
3
namespace Sfneal\GooglePlaces\Actions;
4
5
use Sfneal\GooglePlaces\Actions\Abstracts\PlacesSearchAction;
6
7
class AutocompleteZipAction 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
        foreach ($response['predictions'] as $res) {
19
            $this->results[] = array_fill_keys(
20
                ['id', 'text'],
21
                (new ZipFromPlaceIdAction($this->query, $res['place_id']))->execute()
22
            );
23
        }
24
25
        return [
26
            'total_count' => count($this->results),
27
            'items' => $this->results,
28
        ];
29
    }
30
}
31