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

AutocompleteZipAction::parseResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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