Completed
Push — develop ( 4bf430...c74260 )
by
unknown
18:30
created

Photon::preQuery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Geo\Service;
12
13
use Zend\Http\Client;
14
15
/**
16
 * ${CARET}
17
 * 
18
 * @author Mathias Gelhausen <[email protected]>
19
 * @todo write test 
20
 */
21
class Photon extends AbstractClient
22
{
23
24
25
    protected function setupClient($uri)
26
    {
27
        $client = new Client();
28
        $client->setMethod('GET');
29
30
        $osmTags = [
31
            'tourism','aeroway','railway', 'amenity', 'historic', 'tunnel', 'mountain_pass',
32
            'leisure', 'natural', 'bridge', 'waterway'
33
        ];
34
35
        $osmTags = array_map(function($i) { return urlencode('!' . $i); }, $osmTags);
36
37
        $uri = sprintf(
38
            '%s?osm_tag=%s',
39
            $uri,
40
            implode('&osm_tag=', $osmTags)
41
        );
42
43
        $client->setUri($uri);
44
45
        return $client;
46
    }
47
48
    protected function preQuery($term, array $params)
49
    {
50
        $query = $this->client->getRequest()->getQuery();
51
        $query->set('q', $term);
52
53
        if (isset($params['lang'])) {
54
            $query->set('lang', $params['lang']);
55
        }
56
    }
57
58
    protected function processResult($result)
59
    {
60
        $result = json_decode($result);
61
        $result = $result->features;
62
        $r=[];
63
        foreach ($result as $key => $val) {
64
            $row=['name' => (property_exists($val->properties, 'name') ? $val->properties->name:''),
65
                  'postcode' => (property_exists($val->properties, 'postcode') ? $val->properties->postcode:''),
66
                  'city' =>(property_exists($val->properties, 'city') ? $val->properties->city:''),
67
                  'street' => (property_exists($val->properties, 'street') ? $val->properties->street : ''),
68
                  'state' => (property_exists($val->properties, 'state') ? $val->properties->state : ''),
69
                  'country' => (property_exists($val->properties, 'country') ? $val->properties->country : ''),
70
                  'coordinates' => $val->geometry->coordinates,
71
                  'osm_key' => (property_exists($val->properties, 'osm_key') ? $val->properties->osm_key : ''),
72
                  'osm_value' => (property_exists($val->properties, 'osm_value') ? $val->properties->osm_value : ''),
73
                  //'id' => (property_exists($val->properties, 'osm_id') ? $val->properties->osm_id : uniqid()),
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
                  'data' => json_encode($val),
75
            ];
76
            $row['id'] = 'c:' . (float) $row['coordinates'][0] . ':' . (float) $row['coordinates'][1];
77
            $r[]=$row;
78
        }
79
        return $r;
80
    }
81
}