Current file: /Users/bill/git/HTTP_OAuth/HTTP/OAuth.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 9 / 9 CRAP
100.00%100.00%
100.00% 39 / 39
 
HTTP_OAuth
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 9 / 9
100.00%100.00%
100.00% 39 / 39
 attachLog(Log $log)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 detachLog(Log $detach)
100.00%100.00%
100.00% 1 / 1 3
100.00%100.00%
100.00% 6 / 6
 log($message, $method)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 4 / 4
 debug($message)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 info($message)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 err($message)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 buildHttpQuery(array $params)
100.00%100.00%
100.00% 1 / 1 3
100.00%100.00%
100.00% 11 / 11
 urlencode($item)
100.00%100.00%
100.00% 1 / 1 3
100.00%100.00%
100.00% 7 / 7
 urldecode($item)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 3 / 3


       1                 : <?php                                                                           
       2                 : /**                                                                             
       3                 :  * HTTP_OAuth                                                                   
       4                 :  *                                                                              
       5                 :  * Implementation of the OAuth specification                                    
       6                 :  *                                                                              
       7                 :  * PHP version 5.2.0+                                                           
       8                 :  *                                                                              
       9                 :  * LICENSE: This source file is subject to the New BSD license that is          
      10                 :  * available through the world-wide-web at the following URI:                   
      11                 :  * http://www.opensource.org/licenses/bsd-license.php. If you did not receive   
      12                 :  * a copy of the New BSD License and are unable to obtain it through the web,   
      13                 :  * please send a note to license@php.net so we can mail you a copy immediately. 
      14                 :  *                                                                              
      15                 :  * @category  HTTP                                                              
      16                 :  * @package   HTTP_OAuth                                                        
      17                 :  * @author    Jeff Hodsdon <jeffhodsdon@gmail.com>                              
      18                 :  * @copyright 2009 Jeff Hodsdon <jeffhodsdon@gmail.com>                         
      19                 :  * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
      20                 :  * @link      http://pear.php.net/package/HTTP_OAuth                            
      21                 :  * @link      http://github.com/jeffhodsdon/HTTP_OAuth                          
      22                 :  */                                                                             
      23                 :                                                                                 
      24                 : /**                                                                             
      25                 :  * HTTP_OAuth                                                                   
      26                 :  *                                                                              
      27                 :  * Main HTTP_OAuth class. Contains helper encoding methods.                     
      28                 :  *                                                                              
      29                 :  * @category  HTTP                                                              
      30                 :  * @package   HTTP_OAuth                                                        
      31                 :  * @author    Jeff Hodsdon <jeffhodsdon@gmail.com>                              
      32                 :  * @copyright 2009 Jeff Hodsdon <jeffhodsdon@gmail.com>                         
      33                 :  * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
      34                 :  * @link      http://pear.php.net/package/HTTP_OAuth                            
      35                 :  * @link      http://github.com/jeffhodsdon/HTTP_OAuth                          
      36                 :  */                                                                             
      37                 : abstract class HTTP_OAuth                                                       
      38                 : {                                                                               
      39                 :                                                                                 
      40                 :     /**                                                                         
      41                 :      * Log instances                                                            
      42                 :      *                                                                          
      43                 :      * @var array $logs Instances of PEAR Log handlers                          
      44                 :      */                                                                         
      45                 :     static protected $logs = array();                                           
      46                 :                                                                                 
      47                 :     /**                                                                         
      48                 :      * Attaches an instance of PEAR Log                                         
      49                 :      *                                                                          
      50                 :      * Attached instances of PEAR Log handlers will be logged to                
      51                 :      * through out the use of HTTP_OAuth                                        
      52                 :      *                                                                          
      53                 :      * @param Log $log Instance of a Log                                        
      54                 :      *                                                                          
      55                 :      * @return void                                                             
      56                 :      */                                                                         
      57                 :     static public function attachLog(Log $log)                                  
      58                 :     {                                                                           
      59               2 :         self::$logs[] = $log;                                                   
      60               2 :     }                                                                           
      61                 :                                                                                 
      62                 :     /**                                                                         
      63                 :      * Detaches an instance of PEAR Log                                         
      64                 :      *                                                                          
      65                 :      * @param Log $detach Instance of PEAR Log to detach                        
      66                 :      *                                                                          
      67                 :      * @return void                                                             
      68                 :      */                                                                         
      69                 :     static public function detachLog(Log $detach)                               
      70                 :     {                                                                           
      71               1 :         foreach (self::$logs as $key => $log) {                                 
      72               1 :             if ($log == $detach) {                                              
      73               1 :                 unset(self::$logs[$key]);                                       
      74               1 :             }                                                                   
      75               1 :         }                                                                       
      76               1 :     }                                                                           
      77                 :                                                                                 
      78                 :     /**                                                                         
      79                 :      * Log a message                                                            
      80                 :      *                                                                          
      81                 :      * Announces a message to log to all the attached instances of              
      82                 :      * PEAR Log handlers.  Second argument is the method on Log to call.        
      83                 :      *                                                                          
      84                 :      * @param string $message Message to announce to Logs                       
      85                 :      * @param string $method  Method to log with on Log instances               
      86                 :      *                                                                          
      87                 :      * @return void                                                             
      88                 :      */                                                                         
      89                 :     public function log($message, $method)                                      
      90                 :     {                                                                           
      91              33 :         foreach (self::$logs as $log) {                                         
      92              20 :             $log->$method($message);                                            
      93              33 :         }                                                                       
      94              33 :     }                                                                           
      95                 :                                                                                 
      96                 :     /**                                                                         
      97                 :      * Log debug message                                                        
      98                 :      *                                                                          
      99                 :      * @param string $message Debug message                                     
     100                 :      *                                                                          
     101                 :      * @return void                                                             
     102                 :      */                                                                         
     103                 :     public function debug($message)                                             
     104                 :     {                                                                           
     105              32 :         $this->log($message, 'debug');                                          
     106              32 :     }                                                                           
     107                 :                                                                                 
     108                 :     /**                                                                         
     109                 :      * Log info message                                                         
     110                 :      *                                                                          
     111                 :      * @param string $message Info message                                      
     112                 :      *                                                                          
     113                 :      * @return void                                                             
     114                 :      */                                                                         
     115                 :     public function info($message)                                              
     116                 :     {                                                                           
     117               2 :         $this->log($message, 'info');                                           
     118               2 :     }                                                                           
     119                 :                                                                                 
     120                 :     /**                                                                         
     121                 :      * Log error message                                                        
     122                 :      *                                                                          
     123                 :      * @param string $message Error message                                     
     124                 :      *                                                                          
     125                 :      * @return void                                                             
     126                 :      */                                                                         
     127                 :     public function err($message)                                               
     128                 :     {                                                                           
     129               3 :         $this->log($message, 'err');                                            
     130               3 :     }                                                                           
     131                 :                                                                                 
     132                 :     /**                                                                         
     133                 :      * Build HTTP Query                                                         
     134                 :      *                                                                          
     135                 :      * @param array $params Name => value array of parameters                   
     136                 :      *                                                                          
     137                 :      * @return string HTTP query                                                
     138                 :      */                                                                         
     139                 :     static public function buildHttpQuery(array $params)                        
     140                 :     {                                                                           
     141              10 :         if (empty($params)) {                                                   
     142               1 :             return '';                                                          
     143                 :         }                                                                       
     144                 :                                                                                 
     145               9 :         $keys   = self::urlencode(array_keys($params));                         
     146               9 :         $values = self::urlencode(array_values($params));                       
     147               9 :         $params = array_combine($keys, $values);                                
     148                 :                                                                                 
     149               9 :         uksort($params, 'strcmp');                                              
     150                 :                                                                                 
     151               9 :         $pairs = array();                                                       
     152               9 :         foreach ($params as $key => $value) {                                   
     153               9 :             $pairs[] =  $key . '=' . $value;                                    
     154               9 :         }                                                                       
     155                 :                                                                                 
     156               9 :         return implode('&', $pairs);                                            
     157                 :     }                                                                           
     158                 :                                                                                 
     159                 :     /**                                                                         
     160                 :      * URL Encode                                                               
     161                 :      *                                                                          
     162                 :      * @param mixed $item string or array of items to url encode                
     163                 :      *                                                                          
     164                 :      * @return mixed url encoded string or array of strings                     
     165                 :      */                                                                         
     166                 :     static public function urlencode($item)                                     
     167                 :     {                                                                           
     168              12 :         static $search  = array('+', '%7E');                                    
     169              12 :         static $replace = array('%20', '~');                                    
     170                 :                                                                                 
     171              12 :         if (is_array($item)) {                                                  
     172              10 :             return array_map(array('HTTP_OAuth', 'urlencode'), $item);          
     173                 :         }                                                                       
     174                 :                                                                                 
     175              12 :         if (is_scalar($item) === false) {                                       
     176               1 :             return $item;                                                       
     177                 :         }                                                                       
     178                 :                                                                                 
     179              11 :         return str_replace($search, $replace, rawurlencode($item));             
     180                 :     }                                                                           
     181                 :                                                                                 
     182                 :     /**                                                                         
     183                 :      * URL Decode                                                               
     184                 :      *                                                                          
     185                 :      * @param mixed $item Item to url decode                                    
     186                 :      *                                                                          
     187                 :      * @return string URL decoded string                                        
     188                 :      */                                                                         
     189                 :     static public function urldecode($item)                                     
     190                 :     {                                                                           
     191              14 :         if (is_array($item)) {                                                  
     192              14 :             return array_map(array('HTTP_OAuth', 'urldecode'), $item);          
     193                 :         }                                                                       
     194                 :                                                                                 
     195              14 :         return rawurldecode($item);                                             
     196                 :     }                                                                           
     197                 :                                                                                 
     198                 : }                                                                               
     199                 :                                                                                 
     200                 : ?>                                                                              

Generated by PHP_CodeCoverage 1.0.2 using PHP 5.3.3 and PHPUnit 3.5.6 at Tue Dec 28 21:42:13 PST 2010.