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

AutocompleteZipAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseResponse() 0 13 2
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