Objects.php
Current file: /home/kguest/dev/code/Services_Openstreetmap/Services/OpenStreetMap/Objects.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00% 0 / 1
64.71% 11 / 17 CRAP
84.44% 38 / 45
Services_OpenStreetMap_Objects
0.00% 0 / 1
64.71% 11 / 17 22.66
84.44% 38 / 45
 getXml()
0.00% 0 / 1 2
0.00% 0 / 1
 setXml(SimpleXMLElement $xml)
100.00% 1 / 1 2
100.00% 6 / 6
 setVal($value)
0.00% 0 / 1 2
0.00% 0 / 2
 count()
100.00% 1 / 1 1
100.00% 1 / 1
 rewind()
100.00% 1 / 1 1
100.00% 2 / 2
 current()
100.00% 1 / 1 2
100.00% 9 / 9
 next()
100.00% 1 / 1 1
100.00% 2 / 2
 key()
100.00% 1 / 1 1
100.00% 1 / 1
 valid()
100.00% 1 / 1 1
100.00% 1 / 1
 offsetExists($offset)
0.00% 0 / 1 2
0.00% 0 / 1
 offsetGet($offset)
0.00% 0 / 1 3.01
90.91% 10 / 11
 offsetSet($offset, $value)
0.00% 0 / 1 2
0.00% 0 / 1
 offsetUnset($offset)
0.00% 0 / 1 2
0.00% 0 / 1
 setConfig(Services_OpenStreetMap_Config $config)
100.00% 1 / 1 1
100.00% 2 / 2
 getConfig()
100.00% 1 / 1 1
100.00% 1 / 1
 setTransport($transport)
100.00% 1 / 1 1
100.00% 2 / 2
 getTransport()
100.00% 1 / 1 1
100.00% 1 / 1


       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               0 :         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               2 :         $this->xml = $xml->saveXML();                                              
      57               2 :         $objs = $xml->xpath('//' . $this->getType());                              
      58               2 :         foreach ($objs as $obj) {                                                  
      59               2 :             $this->objects[] = $obj->saveXML();                                    
      60               2 :         }                                                                          
      61               2 :         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               0 :         $this->xml = $value;                                                       
      74               0 :         return $this;                                                              
      75                 :     }                                                                              
      76                 :                                                                                    
      77                 :                                                                                    
      78                 :     /**                                                                            
      79                 :      * Return the number of objects                                                
      80                 :      *                                                                             
      81                 :      * @return void                                                                
      82                 :      */                                                                            
      83                 :     public function count()                                                        
      84                 :     {                                                                              
      85               1 :         return sizeof($this->objects);                                             
      86                 :     }                                                                              
      87                 :                                                                                    
      88                 :     /**                                                                            
      89                 :      * Resets the internal iterator pointer                                        
      90                 :      *                                                                             
      91                 :      * @return void                                                                
      92                 :      */                                                                            
      93                 :     public function rewind()                                                       
      94                 :     {                                                                              
      95               1 :         $this->position = 0;                                                       
      96               1 :     }                                                                              
      97                 :                                                                                    
      98                 :     /**                                                                            
      99                 :      * Return the current object                                                   
     100                 :      *                                                                             
     101                 :      * @return Services_OpenStreetMap_Object                                       
     102                 :      */                                                                            
     103                 :     public function current()                                                      
     104                 :     {                                                                              
     105               1 :         $class = 'Services_OpenStreetMap_' . ucfirst(strtolower($this->getType()));
     106               1 :         $way = new $class();                                                       
     107               1 :         $config = $this->getConfig();                                              
     108               1 :         if (!is_null($config)) {                                                   
     109               1 :             $way->setConfig($config);                                              
     110               1 :         }                                                                          
     111               1 :         $way->setTransport($this->getTransport());                                 
     112               1 :         $way->setXml(simplexml_load_string($this->objects[$this->position]));      
     113               1 :         return $way;                                                               
     114                 :     }                                                                              
     115                 :                                                                                    
     116                 :     /**                                                                            
     117                 :      * Advance the internal iterator pointer                                       
     118                 :      *                                                                             
     119                 :      * @return void                                                                
     120                 :      */                                                                            
     121                 :     public function next()                                                         
     122                 :     {                                                                              
     123               1 :         ++$this->position;                                                         
     124               1 :     }                                                                              
     125                 :                                                                                    
     126                 :     /**                                                                            
     127                 :      * Return the key of the current internal iterator pointer                     
     128                 :      *                                                                             
     129                 :      * @return void                                                                
     130                 :      */                                                                            
     131                 :     public function key()                                                          
     132                 :     {                                                                              
     133               1 :         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               1 :         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               0 :         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               2 :         $class = 'Services_OpenStreetMap_' . ucfirst(strtolower($this->getType()));
     169               2 :         $way = new $class();                                                       
     170               2 :         $config = $this->getConfig();                                              
     171               2 :         if (!is_null($config)) {                                                   
     172               1 :             $way->setConfig($config);                                              
     173               1 :         }                                                                          
     174               2 :         $way->setTransport($this->getTransport());                                 
     175               2 :         if (isset($this->objects[$offset])) {                                      
     176               2 :             $way->setXml(simplexml_load_string($this->objects[$offset]));          
     177               2 :             return $way;                                                           
     178                 :         }                                                                          
     179               0 :     }                                                                              
     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                 :      */                                                                            
     189                 :     public function offsetSet($offset, $value)                                     
     190                 :     {                                                                              
     191               0 :     }                                                                              
     192                 :                                                                                    
     193                 :     /**                                                                            
     194                 :      * Does nothing as collection is read-only: required for ArrayAccess.          
     195                 :      *                                                                             
     196                 :      * @param int $offset N/A.                                                     
     197                 :      *                                                                             
     198                 :      * @return void                                                                
     199                 :      */                                                                            
     200                 :     public function offsetUnset($offset)                                           
     201                 :     {                                                                              
     202               0 :     }                                                                              
     203                 :                                                                                    
     204                 :     /**                                                                            
     205                 :      * Set Config object                                                           
     206                 :      *                                                                             
     207                 :      * @param Services_OpenStreetMap_Config $config Config object                  
     208                 :      *                                                                             
     209                 :      * @return Services_OpenStreetMap_Changeset                                    
     210                 :      */                                                                            
     211                 :     public function setConfig(Services_OpenStreetMap_Config $config)               
     212                 :     {                                                                              
     213               1 :         $this->config = $config;                                                   
     214               1 :         return $this;                                                              
     215                 :     }                                                                              
     216                 :                                                                                    
     217                 :     /**                                                                            
     218                 :      * Get current Config object                                                   
     219                 :      *                                                                             
     220                 :      * @return Services_OpenStreetMap_Config                                       
     221                 :      */                                                                            
     222                 :     public function getConfig()                                                    
     223                 :     {                                                                              
     224               2 :         return $this->config;                                                      
     225                 :     }                                                                              
     226                 :                                                                                    
     227                 :     /**                                                                            
     228                 :      * Set the Transport instance.                                                 
     229                 :      *                                                                             
     230                 :      * @param Services_OpenStreetMap_Transport $transport Transport instance.      
     231                 :      *                                                                             
     232                 :      * @return Services_OpenStreetMap_Config                                       
     233                 :      */                                                                            
     234                 :     public function setTransport($transport)                                       
     235                 :     {                                                                              
     236               1 :         $this->transport = $transport;                                             
     237               1 :         return $this;                                                              
     238                 :     }                                                                              
     239                 :                                                                                    
     240                 :     /**                                                                            
     241                 :      * Retrieve the current Transport instance.                                    
     242                 :      *                                                                             
     243                 :      * @return Services_OpenStreetMap_Transport.                                   
     244                 :      */                                                                            
     245                 :     public function getTransport()                                                 
     246                 :     {                                                                              
     247               2 :         return $this->transport;                                                   
     248                 :     }                                                                              
     249                 : }                                                                                  
     250                 :                                                                                    
     251                 : ?>                                                                                 

Generated by PHP_CodeCoverage 1.1.1 using PHP 5.3.8 and PHPUnit 3.6.7 at Sun Feb 5 13:29:22 GMT 2012.