http://www.phing.info/

Source Code Coverage

Designed for use with PHPUnit, Xdebug and Phing.

Methods: 6 LOC: 167 Statements: 60
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Node.php 100.0% 83.3% 98.5%
   
1
<?php
2
/**
3
 * Node.php
4
 * 25-Apr-2011
5
 *
6
 * PHP Version 5
7
 *
8
 * @category Services
9
 * @package  Services_OpenStreetMap
10
 * @author   Ken Guest <kguest@php.net>
11
 * @license  BSD http://www.opensource.org/licenses/bsd-license.php
12
 * @version  Release: @package_version@
13
 * @link     Node.php
14
*/
15
16
/**
17
 * Services_OpenStreetMap_Node
18
 *
19
 * @category Services
20
 * @package  Services_OpenStreetMap
21
 * @author   Ken Guest <kguest@php.net>
22
 * @license  BSD http://www.opensource.org/licenses/bsd-license.php
23
 * @link     Node.php
24
 */
25
class Services_OpenStreetMap_Node extends Services_OpenStreetMap_Object
26 1
{
27
    protected $type = 'node';
28
29
    /**
30
     * Latitude of node
31
     *
32
     * @return float
33
     */
34
    public function getLat()
35
    {
36 4
        return (float) $this->getAttributes()->lat;
37
    }
38
39
    /**
40
     * Longitude of node
41
     *
42
     * @return float
43
     */
44
    public function getLon()
45
    {
46 4
        return (float) $this->getAttributes()->lon;
47
    }
48
49
    /**
50
     * set the Latitude of the node
51
     *
52
     * <pre>
53
     * $node->setLat($lat)->setLon($lon);
54
     * </pre>
55
     *
56
     * @param float $value Latitude (-180 < y < 180)
57
     *
58
     * @return Services_OpenStreetMap_Node
59
     * @throws Services_OpenStreetMap_InvalidArgumentException
60
     */
61
    public function setLat($value)
62
    {
63 12
        if (!is_numeric($value)) {
64 1
            throw new Services_OpenStreetMap_InvalidArgumentException(
65
                'Latitude must be numeric'
66 1
            );
67 1
        }
68 11
        if ($value < -180) {
69 1
            throw new Services_OpenStreetMap_InvalidArgumentException(
70
                'Latitude can\'t be less than -180'
71 1
            );
72 1
        }
73 10
        if ($value > 180) {
74 1
            throw new Services_OpenStreetMap_InvalidArgumentException(
75
                'Latitude can\'t be greater than 180'
76 1
            );
77 1
        }
78 9
        return $this;
79
    }
80
81
    /**
82
     * set the Longitude of the node
83
     *
84
     * <pre>
85
     * $node->setLat($lat)->setLon($lon);
86
     * </pre>
87
     *
88
     * @param float $value Longitude (-90 < x < 90)
89
     *
90
     * @return Services_OpenStreetMap_Node
91
     * @throws Services_OpenStreetMap_InvalidArgumentException
92
     */
93
    public function setLon($value)
94
    {
95 9
        if (!is_numeric($value)) {
96 1
            throw new Services_OpenStreetMap_InvalidArgumentException(
97
                'Longitude must be numeric'
98 1
            );
99 1
        }
100 8
        if ($value < -90) {
101 1
            throw new Services_OpenStreetMap_InvalidArgumentException(
102
                'Longitude can\'t be less than -90'
103 1
            );
104 1
        }
105 7
        if ($value > 90) {
106 1
            throw new Services_OpenStreetMap_InvalidArgumentException(
107
                'Longitude can\'t be greater than 90'
108 1
            );
109 1
        }
110 6
        return $this;
111
    }
112
113
    /**
114
     * Return address [tags], as an array, if set.
115
     *
116
     * @return array
117
     */
118
    public function getAddress()
119
    {
120
        $ret  = array(
121 1
            'addr_housename' => null,
122 1
            'addr_housenumber' => null,
123 1
            'addr_street' => null,
124 1
            'addr_city' => null,
125
            'addr_country' => null
126 1
        );
127 1
        $tags = $this->getTags();
128 1
        $detailsSet = false;
129 1
        foreach ($tags as $key => $value) {
130 1
            if (strpos($key, 'addr') === 0) {
131 1
                $ret[str_replace(':', '_', $key)] = $value;
132 1
                $detailsSet = true;
133 1
            }
134 1
        }
135 1
        if (!$detailsSet) {
136 1
            $ret = null;
137 1
        }
138 1
        return $ret;
139
    }
140
141
    /**
142
     * Return a collection of Services_OpenStreetMap_Way objects that use the
143
     * node in question.
144
     *
145
     * @return Services_OpenStreetMap_Ways
146
     */
147
    public function getWays()
148
    {
149 1
        $config = $this->getConfig();
150 1
        $id = $this->getId();
151 1
        $url = $config->getValue('server')
152
            . 'api/'
153 1
            . $config->getValue('api_version')
154 1
            . "/node/$id/ways";
155 1
        $response = $this->getTransport()->getResponse($url);
156 1
        $obj = new Services_OpenStreetMap_Ways();
157 1
        $sxe = @simplexml_load_string($response->getBody());
158 1
        if ($sxe === false) {
159
            $obj->setVal(trim($response->getBody()));
160
        } else {
161 1
            $obj->setXml($sxe);
162
        }
163 1
        return $obj;
164
    }
165
}
166
// vim:set et ts=4 sw=4:
167
?>


Report generated at 2012-10-02T18:40:35+01:00