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

  Coverage
  Classes Functions / Methods Lines
Total
100.00% 1 / 1
100.00% 12 / 12 CRAP
100.00% 45 / 45
Services_Openstreetmap_User
100.00% 1 / 1
100.00% 12 / 12 20
100.00% 45 / 45
 setXml(SimpleXMLElement $xml)
100.00% 1 / 1 1
100.00% 3 / 3
 setPreferencesXml($xml)
100.00% 1 / 1 1
100.00% 3 / 3
 getAttributes()
100.00% 1 / 1 1
100.00% 1 / 1
 getDisplayName()
100.00% 1 / 1 1
100.00% 1 / 1
 getAccountCreated()
100.00% 1 / 1 1
100.00% 1 / 1
 getDescription()
100.00% 1 / 1 1
100.00% 2 / 2
 getId()
100.00% 1 / 1 1
100.00% 1 / 1
 getImage()
100.00% 1 / 1 2
100.00% 4 / 4
 getLanguages()
100.00% 1 / 1 3
100.00% 9 / 9
 getLat()
100.00% 1 / 1 2
100.00% 4 / 4
 getLon()
100.00% 1 / 1 2
100.00% 5 / 5
 getPreferences()
100.00% 1 / 1 4
100.00% 11 / 11


       1                 : <?php                                                                          
       2                 : /**                                                                            
       3                 :  * User.php                                                                    
       4                 :  * 07-Sep-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     User.php                                                          
      14                 : */                                                                             
      15                 :                                                                                
      16                 : /**                                                                            
      17                 :  * Services_Openstreetmap_User                                                 
      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     User.php                                                          
      24                 :  */                                                                            
      25                 : class Services_Openstreetmap_User                                              
      26                 : {                                                                              
      27                 :                                                                                
      28                 :     protected $preferences = array();                                          
      29                 :                                                                                
      30                 :     /**                                                                        
      31                 :      * setXml                                                                  
      32                 :      *                                                                         
      33                 :      * @param SimpleXMLElement $xml XML describing a user.                     
      34                 :      *                                                                         
      35                 :      * @return Services_Openstreetmap_User                                     
      36                 :      */                                                                        
      37                 :     public function setXml(SimpleXMLElement $xml)                              
      38                 :     {                                                                          
      39               3 :         $this->xml = $xml->saveXML();                                          
      40               3 :         $this->obj = $xml->xpath('//user');                                    
      41               3 :         return $this;                                                          
      42                 :     }                                                                          
      43                 :                                                                                
      44                 :     /**                                                                        
      45                 :      * setPreferencesXml                                                       
      46                 :      *                                                                         
      47                 :      * @param mixed $xml XML describing a user's preferences.                  
      48                 :      *                                                                         
      49                 :      * @return void                                                            
      50                 :      */                                                                        
      51                 :     public function setPreferencesXml($xml)                                    
      52                 :     {                                                                          
      53               3 :         $this->prefXml = $xml;                                                 
      54               3 :         $this->prefObj = simplexml_load_string($xml)->xpath('//preferences');  
      55               3 :     }                                                                          
      56                 :                                                                                
      57                 :     /**                                                                        
      58                 :      * Return the attributes set for this user instance.                       
      59                 :      *                                                                         
      60                 :      * @return string getAttributes()                                          
      61                 :      */                                                                        
      62                 :     public function getAttributes()                                            
      63                 :     {                                                                          
      64               1 :         return $this->obj[0]->attributes();                                    
      65                 :     }                                                                          
      66                 :                                                                                
      67                 :     /**                                                                        
      68                 :      * Return the display name of the user.                                    
      69                 :      *                                                                         
      70                 :      * @return string display name of user.                                    
      71                 :      */                                                                        
      72                 :     public function getDisplayName()                                           
      73                 :     {                                                                          
      74               1 :         return (string) $this->getAttributes()->display_name;                  
      75                 :     }                                                                          
      76                 :                                                                                
      77                 :     /**                                                                        
      78                 :      * Retrieve date, as a string, representing when the user's account was    
      79                 :      * created.                                                                
      80                 :      *                                                                         
      81                 :      * @return string                                                          
      82                 :      */                                                                        
      83                 :     public function getAccountCreated()                                        
      84                 :     {                                                                          
      85               1 :         return (string) $this->getAttributes()->account_created;               
      86                 :     }                                                                          
      87                 :                                                                                
      88                 :     /**                                                                        
      89                 :      * Return the description set for the user.                                
      90                 :      *                                                                         
      91                 :      * @return string                                                          
      92                 :      */                                                                        
      93                 :     public function getDescription()                                           
      94                 :     {                                                                          
      95               1 :         $desc = simplexml_load_string($this->xml)->xpath('//user/description');
      96               1 :         return (string) trim($desc[0]);                                        
      97                 :     }                                                                          
      98                 :                                                                                
      99                 :     /**                                                                        
     100                 :      * Retrieve the id of the user.                                            
     101                 :      *                                                                         
     102                 :      * @return integer id of the object                                        
     103                 :      */                                                                        
     104                 :     public function getId()                                                    
     105                 :     {                                                                          
     106               1 :         return (float) $this->getAttributes()->id;                             
     107                 :     }                                                                          
     108                 :                                                                                
     109                 :     /**                                                                        
     110                 :      * Return href to user's profile image, null if not set.                   
     111                 :      *                                                                         
     112                 :      * @return string                                                          
     113                 :      */                                                                        
     114                 :     public function getImage()                                                 
     115                 :     {                                                                          
     116               2 :         $img = simplexml_load_string($this->xml)->xpath('//user/img');         
     117               2 :         if (empty($img)) {                                                     
     118               1 :             return null;                                                       
     119                 :         }                                                                      
     120               1 :         return (string) $img[0]->attributes()->href;                           
     121                 :     }                                                                          
     122                 :                                                                                
     123                 :     /**                                                                        
     124                 :      * Return an array of the user's preferred languages.                      
     125                 :      *                                                                         
     126                 :      * @return array                                                           
     127                 :      */                                                                        
     128                 :     public function getLanguages()                                             
     129                 :     {                                                                          
     130               1 :         $langers = array();                                                    
     131               1 :         $cxml = simplexml_load_string($this->xml);                             
     132               1 :         $languages = $cxml->xpath('//user/languages');                         
     133               1 :         foreach ($languages[0]->children() as $child) {                        
     134               1 :             if ($child->getName() == 'lang') {                                 
     135               1 :                 $langers[] = (string) $child[0];                               
     136               1 :             }                                                                  
     137               1 :         }                                                                      
     138               1 :         return $langers;                                                       
     139                 :     }                                                                          
     140                 :                                                                                
     141                 :     /**                                                                        
     142                 :      * Latitude of 'home' setting for user.                                    
     143                 :      *                                                                         
     144                 :      * @return float                                                           
     145                 :      */                                                                        
     146                 :     public function getLat()                                                   
     147                 :     {                                                                          
     148               2 :         $home = simplexml_load_string($this->xml)->xpath('//user/home');       
     149               2 :         if (empty($home)) {                                                    
     150               1 :             return null;                                                       
     151                 :         }                                                                      
     152               1 :         return (float) $home[0]->attributes()->lat;                            
     153                 :     }                                                                          
     154                 :                                                                                
     155                 :     /**                                                                        
     156                 :      * Longitude of 'home' setting for user.                                   
     157                 :      *                                                                         
     158                 :      * @return float                                                           
     159                 :      */                                                                        
     160                 :     public function getLon()                                                   
     161                 :     {                                                                          
     162               2 :         $cxml = simplexml_load_string($this->xml);                             
     163               2 :         $home = $cxml->xpath('//user/home');                                   
     164               2 :         if (empty($home)) {                                                    
     165               1 :             return null;                                                       
     166                 :         }                                                                      
     167               1 :         return (float) $home[0]->attributes()->lon;                            
     168                 :     }                                                                          
     169                 :                                                                                
     170                 :     /**                                                                        
     171                 :      * return an array of the user's preferences.                              
     172                 :      *                                                                         
     173                 :      * @return array                                                           
     174                 :      */                                                                        
     175                 :     public function getPreferences()                                           
     176                 :     {                                                                          
     177               1 :         if ($this->preferences == array()) {                                   
     178                 :                                                                                
     179               1 :             $preferences = array();                                            
     180               1 :             foreach ($this->prefObj[0]->children() as $child) {                
     181               1 :                 $key = (string) $child->attributes()->k;                       
     182               1 :                 if ($key != '') {                                              
     183               1 :                     $preferences[$key] = (string) $child->attributes()->v;     
     184               1 :                 }                                                              
     185               1 :             }                                                                  
     186               1 :             $this->preferences = $preferences;                                 
     187               1 :         }                                                                      
     188               1 :         return $this->preferences;                                             
     189                 :     }                                                                          
     190                 :                                                                                
     191                 : }                                                                              
     192                 : // vim:set et ts=4 sw=4:                                                       
     193                 : ?>                                                                             

Generated by PHP_CodeCoverage 1.1.1 using PHP 5.3.8 and PHPUnit 3.6.7 at Thu Feb 2 23:20:15 GMT 2012.