http://www.phing.info/

Source Code Coverage

Designed for use with PHPUnit, Xdebug and Phing.

Methods: 17 LOC: 255 Statements: 44
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Objects.php 100.0% 76.5% 93.4%
   
1
<?php
2
/**
3
 * Objects.php
4
 * 01-Oct-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
 * @link     Ways.php
13
 */
14
15
/**
16
 * Services_OpenStreetMap_Objects
17
 *
18
 * @category Services
19
 * @package  Services_OpenStreetMap
20
 * @author   Ken Guest <kguest@php.net>
21
 * @license  BSD http://www.opensource.org/licenses/bsd-license.php
22
 * @link     Objects.php
23
 */
24
class Services_OpenStreetMap_Objects implements Iterator, ArrayAccess, Countable
25
{
26
27
    protected $xml = null;
28
29
    protected $objects = null;
30
31
    protected $position = 0;
32
33
    protected $transport = null;
34
35
    protected $config = null;
36
37
    /**
38
     * getXml
39
     *
40
     * @return string
41
     */
42
    public function getXml()
43
    {
44
        return $this->xml;
45
    }
46
47
    /**
48
     * setXml
49
     *
50
     * @param mixed $xml OSM XML
51
     *
52
     * @return void
53
     */
54
    public function setXml(SimpleXMLElement $xml)
55
    {
56 15
        $this->xml = $xml->saveXML();
57 15
        $objs = $xml->xpath('//' . $this->getType());
58 15
        foreach ($objs as $obj) {
59 15
            $this->objects[] = $obj->saveXML();
60 15
        }
61 15
        return $this;
62
    }
63
64
    /**
65
     * Store a specified value.
66
     *
67
     * @param string $value Most likely an id value, returned from the server.
68
     *
69
     * @return void
70
     */
71
    public function setVal($value)
72
    {
73 1
        $this->xml = $value;
74 1
        return $this;
75
    }
76
77
78
    /**
79
     * Return the number of objects
80
     *
81
     * @return void
82
     */
83
    public function count()
84
    {
85 6
        return sizeof($this->objects);
86
    }
87
88
    /**
89
     * Resets the internal iterator pointer
90
     *
91
     * @return void
92
     */
93
    public function rewind()
94
    {
95 9
        $this->position = 0;
96
    }
97
98
    /**
99
     * Return the current object
100
     *
101
     * @return Services_OpenStreetMap_Object
102
     */
103
    public function current()
104
    {
105 8
        $class = 'Services_OpenStreetMap_' . ucfirst(strtolower($this->getType()));
106 8
        $way = new $class();
107 8
        $config = $this->getConfig();
108 8
        if (!is_null($config)) {
109 6
            $way->setConfig($config);
110 6
        }
111 8
        $way->setTransport($this->getTransport());
112 8
        $way->setXml(simplexml_load_string($this->objects[$this->position]));
113 8
        return $way;
114
    }
115
116
    /**
117
     * Advance the internal iterator pointer
118
     *
119
     * @return void
120
     */
121
    public function next()
122
    {
123 7
        ++$this->position;
124
    }
125
126
    /**
127
     * Return the key of the current internal iterator pointer
128
     *
129
     * @return void
130
     */
131
    public function key()
132
    {
133 5
        return $this->position;
134
    }
135
136
    /**
137
     * Returns whether the current internal iterator pointer is pointing to an
138
     * existing/valid value.
139
     *
140
     * @return bool
141
     */
142
    public function valid()
143
    {
144 9
        return isset($this->objects[$this->position]);
145
    }
146
147
    /**
148
     * Check if the specified offset exists.
149
     *
150
     * @param int $offset N/A.
151
     *
152
     * @return bool
153
     */
154
    public function offsetExists($offset)
155
    {
156
        return isset($this->objects[$offset]);
157
    }
158
159
    /**
160
     * Get object from the specified offset.
161
     *
162
     * @param int $offset N/A.
163
     *
164
     * @return Services_OpenStreetMap_Object
165
     */
166
    public function offsetGet($offset)
167
    {
168 5
        $class = 'Services_OpenStreetMap_' . ucfirst(strtolower($this->getType()));
169 5
        $way = new $class();
170 5
        $config = $this->getConfig();
171 5
        if (!is_null($config)) {
172 1
            $way->setConfig($config);
173 1
        }
174 5
        $way->setTransport($this->getTransport());
175 5
        if (isset($this->objects[$offset])) {
176 5
            $way->setXml(simplexml_load_string($this->objects[$offset]));
177 5
            return $way;
178 5
        }
179
    }
180
181
    /**
182
     * Does nothing as collection is read-only: required for ArrayAccess.
183
     *
184
     * @param int                           $offset N/A
185
     * @param Services_OpenStreetMap_Object $value  N/A
186
     *
187
     * @return void
188
     * @throws LogicException
189
     */
190
    public function offsetSet($offset, $value)
191
    {
192
        throw new LogicException('Changing properties not implemented');
193
    }
194
195
    /**
196
     * Does nothing as collection is read-only: required for ArrayAccess.
197
     *
198
     * @param int $offset N/A.
199
     *
200
     * @return void
201
     * @throws LogicException
202
     */
203
    public function offsetUnset($offset)
204
    {
205
        throw new LogicException('Changing properties not implemented');
206
    }
207
208
    /**
209
     * Set Config object
210
     *
211
     * @param Services_OpenStreetMap_Config $config Config object
212
     *
213
     * @return Services_OpenStreetMap_Changeset
214
     */
215
    public function setConfig(Services_OpenStreetMap_Config $config)
216
    {
217 7
        $this->config = $config;
218 7
        return $this;
219
    }
220
221
    /**
222
     * Get current Config object
223
     *
224
     * @return Services_OpenStreetMap_Config
225
     */
226
    public function getConfig()
227
    {
228 11
        return $this->config;
229
    }
230
231
    /**
232
     * Set the Transport instance.
233
     *
234
     * @param Services_OpenStreetMap_Transport $transport Transport instance.
235
     *
236
     * @return Services_OpenStreetMap_Config
237
     */
238
    public function setTransport($transport)
239
    {
240 7
        $this->transport = $transport;
241 7
        return $this;
242
    }
243
244
    /**
245
     * Retrieve the current Transport instance.
246
     *
247
     * @return Services_OpenStreetMap_Transport.
248
     */
249
    public function getTransport()
250
    {
251 11
        return $this->transport;
252
    }
253
}
254
255
?>


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