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

  Coverage
  Classes Functions / Methods Lines
Total
0.00% 0 / 1
0.00% 0 / 6 CRAP
15.38% 8 / 52
Services_OpenStreetMap_Node
0.00% 0 / 1
0.00% 0 / 6 171.09
15.38% 8 / 52
 getLat()
0.00% 0 / 1 2
0.00% 0 / 1
 getLon()
0.00% 0 / 1 2
0.00% 0 / 1
 setLat($value)
0.00% 0 / 1 7.46
40.00% 4 / 10
 setLon($value)
0.00% 0 / 1 7.46
40.00% 4 / 10
 getAddress()
0.00% 0 / 1 20
0.00% 0 / 17
 getWays()
0.00% 0 / 1 6
0.00% 0 / 13


       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                 : {                                                                            
      27                 :     protected $type = 'node';                                                
      28                 :                                                                              
      29                 :     /**                                                                      
      30                 :      * Latitude of node                                                      
      31                 :      *                                                                       
      32                 :      * @return float                                                         
      33                 :      */                                                                      
      34                 :     public function getLat()                                                 
      35                 :     {                                                                        
      36               0 :         return (float) $this->getAttributes()->lat;                          
      37                 :     }                                                                        
      38                 :                                                                              
      39                 :     /**                                                                      
      40                 :      * Longitude of node                                                     
      41                 :      *                                                                       
      42                 :      * @return float                                                         
      43                 :      */                                                                      
      44                 :     public function getLon()                                                 
      45                 :     {                                                                        
      46               0 :         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               1 :         if (!is_numeric($value)) {                                           
      64               0 :             throw new Services_OpenStreetMap_InvalidArgumentException(       
      65                 :                 'Latitude must be numeric'                                   
      66               0 :             );                                                               
      67                 :         }                                                                    
      68               1 :         if ($value < -180) {                                                 
      69               0 :             throw new Services_OpenStreetMap_InvalidArgumentException(       
      70                 :                 'Latitude can\'t be less than -180'                          
      71               0 :             );                                                               
      72                 :         }                                                                    
      73               1 :         if ($value > 180) {                                                  
      74               0 :             throw new Services_OpenStreetMap_InvalidArgumentException(       
      75                 :                 'Latitude can\'t be greater than 180'                        
      76               0 :             );                                                               
      77                 :         }                                                                    
      78               1 :         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               1 :         if (!is_numeric($value)) {                                           
      96               0 :             throw new Services_OpenStreetMap_InvalidArgumentException(       
      97                 :                 'Longitude must be numeric'                                  
      98               0 :             );                                                               
      99                 :         }                                                                    
     100               1 :         if ($value < -90) {                                                  
     101               0 :             throw new Services_OpenStreetMap_InvalidArgumentException(       
     102                 :                 'Longitude can\'t be less than -90'                          
     103               0 :             );                                                               
     104                 :         }                                                                    
     105               1 :         if ($value > 90) {                                                   
     106               0 :             throw new Services_OpenStreetMap_InvalidArgumentException(       
     107                 :                 'Longitude can\'t be greater than 90'                        
     108               0 :             );                                                               
     109                 :         }                                                                    
     110               1 :         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               0 :             'addr_housename' => null,                                        
     122               0 :             'addr_housenumber' => null,                                      
     123               0 :             'addr_street' => null,                                           
     124               0 :             'addr_city' => null,                                             
     125                 :             'addr_country' => null                                           
     126               0 :         );                                                                   
     127               0 :         $tags = $this->getTags();                                            
     128               0 :         $detailsSet = false;                                                 
     129               0 :         foreach ($tags as $key => $value) {                                  
     130               0 :             if (strpos($key, 'addr') === 0) {                                
     131               0 :                 $ret[str_replace(':', '_', $key)] = $value;                  
     132               0 :                 $detailsSet = true;                                          
     133               0 :             }                                                                
     134               0 :         }                                                                    
     135               0 :         if (!$detailsSet) {                                                  
     136               0 :             $ret = null;                                                     
     137               0 :         }                                                                    
     138               0 :         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               0 :         $config = $this->getConfig();                                        
     150               0 :         $id = $this->getId();                                                
     151               0 :         $url = $config->getValue('server')                                   
     152                 :             . 'api/'                                                         
     153               0 :             . $config->getValue('api_version')                               
     154               0 :             . "/node/$id/ways";                                              
     155               0 :         $response = $this->getTransport()->getResponse($url);                
     156               0 :         $obj = new Services_OpenStreetMap_Ways();                            
     157               0 :         $sxe = @simplexml_load_string($response->getBody());                 
     158               0 :         if ($sxe === false) {                                                
     159               0 :             $obj->setVal(trim($response->getBody()));                        
     160               0 :         } else {                                                             
     161               0 :             $obj->setXml($sxe);                                              
     162                 :         }                                                                    
     163               0 :         return $obj;                                                         
     164                 :     }                                                                        
     165                 : }                                                                            
     166                 : // vim:set et ts=4 sw=4:                                                     
     167                 : ?>                                                                           

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.