Completed
Push — master ( fd983c...6ef91a )
by Maxime
04:57
created

Reverse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Class Reverse
4
 *
5
 * @package      maxh\nominatim
6
 * @author       Maxime Hélias <[email protected]>
7
 */
8
9
namespace maxh\Nominatim;
10
11
use maxh\Nominatim\Exceptions\InvalidParameterException;
12
13
/**
14
 * Reverse Geocoding a OSM nominatim service for places.
15
 *
16
 * @see http://wiki.openstreetmap.org/wiki/Nominatim
17
 */
18
class Reverse extends Query
19
{
20
21
    /**
22
     * OSM Type accepted (Node/Way/Relation)
23
     * @var array
24
     */
25
    public $osmType = ['N', 'W', 'R'];
26
27
28
    /**
29
     * Constructo
30
     * @param array $query Default value for this query
31
     */
32 5
    public function __construct(array $query = [])
33
    {
34 5
        parent::__construct();
35
36 5
        $this->setPath('reverse');
37 5
    }
38
39
    // -- Builder methods ------------------------------------------------------
40
41
    /**
42
     * [osmType description]
43
     *
44
     * @param  string $type
45
     *
46
     * @return maxh\Nominatim\Reverse
47
     * @throws maxh\Nominatim\Exceptions\InvalidParameterException  if osm type is not supported
48
     */
49
    public function osmType($type)
50
    {
51
        if (in_array($type, $this->osmType)) {
52
            $this->query['osm_type'] = $type;
53
54
            return $this;
55
        }
56
57
        throw new InvalidParameterException("OSM Type is not supported");
58
    }
59
60
    /**
61
     * A specific osm node / way / relation to return an address for.
62
     *
63
     * @param  integer $id
64
     *
65
     * @return maxh\Nominatim\Reverse
66
     */
67
    public function osmId($id)
68
    {
69
        $this->query['osm_id'] = $id;
70
71
        return $this;
72
    }
73
74
    /**
75
     * The location to generate an address for
76
     *
77
     * @param  float $lat The latitude
78
     * @param  float $lon The longitude
79
     *
80
     * @return maxh\Nominatim\Reverse
81
     */
82 1
    public function latlon($lat, $lon)
83
    {
84 1
        $this->query['lat'] = $lat;
85
86 1
        $this->query['lon'] = $lon;
87
88 1
        return $this;
89
    }
90
91
    /**
92
     * Level of detail required where 0 is country and 18 is house/building
93
     *
94
     * @param  integer $zoom
95
     *
96
     * @return maxh\Nominatim\Reverse
97
     */
98
    public function zoom($zoom)
99
    {
100
        $this->query['zoom'] = strval($zoom);
101
102
        return $this;
103
    }
104
}
105