Current file: /Users/bill/git/HTTP_OAuth/HTTP/OAuth/Message.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% 13 / 13 CRAP
100.00%100.00%
100.00% 39 / 39
 
HTTP_OAuth_Message
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 13 / 13
100.00%100.00%
100.00% 39 / 39
 getOAuthParameters()
100.00%100.00%
100.00% 1 / 1 3
100.00%100.00%
100.00% 8 / 8
 getParameters()
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 3 / 3
 setParameters(array $params)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 4 / 4
 getSignatureMethod()
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 3 / 3
 __get($var)
100.00%100.00%
100.00% 1 / 1 3
100.00%100.00%
100.00% 7 / 7
 __set($var, $val)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 offsetExists($offset)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 offsetGet($offset)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 offsetSet($offset, $value)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 offsetUnset($offset)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 count()
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 getIterator()
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 prefixParameter($param)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 4 / 4


       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                 : require_once 'HTTP/OAuth.php';                                                  
      25                 :                                                                                 
      26                 : /**                                                                             
      27                 :  * HTTP_OAuth_Message                                                           
      28                 :  *                                                                              
      29                 :  * Main message class for Request and Response classes to extend from.  Provider
      30                 :  * and Consumer packages use this class as there parent for the request/response
      31                 :  * classes. This contains specification parameters handling and ArrayAccess,    
      32                 :  * Countable, IteratorAggregate features.                                       
      33                 :  *                                                                              
      34                 :  * @category  HTTP                                                              
      35                 :  * @package   HTTP_OAuth                                                        
      36                 :  * @author    Jeff Hodsdon <jeffhodsdon@gmail.com>                              
      37                 :  * @copyright 2009 Jeff Hodsdon <jeffhodsdon@gmail.com>                         
      38                 :  * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
      39                 :  * @link      http://pear.php.net/package/HTTP_OAuth                            
      40                 :  * @link      http://github.com/jeffhodsdon/HTTP_OAuth                          
      41                 :  */                                                                             
      42                 : abstract class HTTP_OAuth_Message                                               
      43                 : extends HTTP_OAuth                                                              
      44                 : implements ArrayAccess, Countable, IteratorAggregate                            
      45                 : {                                                                               
      46                 :                                                                                 
      47                 :     /**                                                                         
      48                 :      * OAuth Parameters                                                         
      49                 :      *                                                                          
      50                 :      * @var string $oauthParams OAuth parameters                                
      51                 :      */                                                                         
      52                 :     static protected $oauthParams = array(                                      
      53                 :         'consumer_key',                                                         
      54                 :         'token',                                                                
      55                 :         'token_secret',                                                         
      56                 :         'signature_method',                                                     
      57                 :         'signature',                                                            
      58                 :         'timestamp',                                                            
      59                 :         'nonce',                                                                
      60                 :         'verifier',                                                             
      61                 :         'version',                                                              
      62                 :         'callback',                                                             
      63                 :         'session_handle'                                                        
      64                 :     );                                                                          
      65                 :                                                                                 
      66                 :     /**                                                                         
      67                 :      * Parameters                                                               
      68                 :      *                                                                          
      69                 :      * @var array $parameters Parameters                                        
      70                 :      */                                                                         
      71                 :     protected $parameters = array();                                            
      72                 :                                                                                 
      73                 :     /**                                                                         
      74                 :      * Get OAuth specific parameters                                            
      75                 :      *                                                                          
      76                 :      * @return array OAuth specific parameters                                  
      77                 :      */                                                                         
      78                 :     public function getOAuthParameters()                                        
      79                 :     {                                                                           
      80               4 :         $params = array();                                                      
      81               4 :         foreach (self::$oauthParams as $param) {                                
      82               4 :             if ($this->$param !== null) {                                       
      83               4 :                 $params[$this->prefixParameter($param)] = $this->$param;        
      84               4 :             }                                                                   
      85               4 :         }                                                                       
      86                 :                                                                                 
      87               4 :         ksort($params);                                                         
      88                 :                                                                                 
      89               4 :         return $params;                                                         
      90                 :     }                                                                           
      91                 :                                                                                 
      92                 :     /**                                                                         
      93                 :      * Get parameters                                                           
      94                 :      *                                                                          
      95                 :      * @return array Request's parameters                                       
      96                 :      */                                                                         
      97                 :     public function getParameters()                                             
      98                 :     {                                                                           
      99               8 :         $params = $this->parameters;                                            
     100               8 :         ksort($params);                                                         
     101                 :                                                                                 
     102               8 :         return $params;                                                         
     103                 :     }                                                                           
     104                 :                                                                                 
     105                 :     /**                                                                         
     106                 :      * Set parameters                                                           
     107                 :      *                                                                          
     108                 :      * @param array $params Name => value pair array of parameters              
     109                 :      *                                                                          
     110                 :      * @return void                                                             
     111                 :      */                                                                         
     112                 :     public function setParameters(array $params)                                
     113                 :     {                                                                           
     114              20 :         foreach ($params as $name => $value) {                                  
     115              20 :             $this->parameters[$this->prefixParameter($name)] = $value;          
     116              20 :         }                                                                       
     117              20 :     }                                                                           
     118                 :                                                                                 
     119                 :     /**                                                                         
     120                 :      * Get signature method                                                     
     121                 :      *                                                                          
     122                 :      * @return string Signature method                                          
     123                 :      */                                                                         
     124                 :     public function getSignatureMethod()                                        
     125                 :     {                                                                           
     126               5 :         if ($this->oauth_signature_method !== null) {                           
     127               3 :             return $this->oauth_signature_method;                               
     128                 :         }                                                                       
     129                 :                                                                                 
     130               2 :         return 'HMAC-SHA1';                                                     
     131                 :     }                                                                           
     132                 :                                                                                 
     133                 :     /**                                                                         
     134                 :      * Get                                                                      
     135                 :      *                                                                          
     136                 :      * @param string $var Variable to get                                       
     137                 :      *                                                                          
     138                 :      * @return mixed Parameter if exists, else null                             
     139                 :      */                                                                         
     140                 :     public function __get($var)                                                 
     141                 :     {                                                                           
     142               8 :         $var = $this->prefixParameter($var);                                    
     143               8 :         if (array_key_exists($var, $this->parameters)) {                        
     144               7 :             return $this->parameters[$var];                                     
     145                 :         }                                                                       
     146                 :                                                                                 
     147               6 :         $method = 'get' . ucfirst($var);                                        
     148               6 :         if (method_exists($this, $method)) {                                    
     149               1 :             return $this->$method();                                            
     150                 :         }                                                                       
     151                 :                                                                                 
     152               5 :         return null;                                                            
     153                 :     }                                                                           
     154                 :                                                                                 
     155                 :     /**                                                                         
     156                 :      * Set                                                                      
     157                 :      *                                                                          
     158                 :      * @param string $var Name of the variable                                  
     159                 :      * @param mixed  $val Value of the variable                                 
     160                 :      *                                                                          
     161                 :      * @return void                                                             
     162                 :      */                                                                         
     163                 :     public function __set($var, $val)                                           
     164                 :     {                                                                           
     165               6 :         $this->parameters[$this->prefixParameter($var)] = $val;                 
     166               6 :     }                                                                           
     167                 :                                                                                 
     168                 :     /**                                                                         
     169                 :      * Offset exists                                                            
     170                 :      *                                                                          
     171                 :      * @param string $offset Name of the offset                                 
     172                 :      *                                                                          
     173                 :      * @return bool Offset exists or not                                        
     174                 :      */                                                                         
     175                 :     public function offsetExists($offset)                                       
     176                 :     {                                                                           
     177               3 :         return isset($this->parameters[$this->prefixParameter($offset)]);       
     178                 :     }                                                                           
     179                 :                                                                                 
     180                 :     /**                                                                         
     181                 :      * Offset get                                                               
     182                 :      *                                                                          
     183                 :      * @param string $offset Name of the offset                                 
     184                 :      *                                                                          
     185                 :      * @return string Offset value                                              
     186                 :      */                                                                         
     187                 :     public function offsetGet($offset)                                          
     188                 :     {                                                                           
     189               3 :         return $this->parameters[$this->prefixParameter($offset)];              
     190                 :     }                                                                           
     191                 :                                                                                 
     192                 :     /**                                                                         
     193                 :      * Offset set                                                               
     194                 :      *                                                                          
     195                 :      * @param string $offset Name of the offset                                 
     196                 :      * @param string $value  Value of the offset                                
     197                 :      *                                                                          
     198                 :      * @return void                                                             
     199                 :      */                                                                         
     200                 :     public function offsetSet($offset, $value)                                  
     201                 :     {                                                                           
     202               6 :         $this->parameters[$this->prefixParameter($offset)] = $value;            
     203               6 :     }                                                                           
     204                 :                                                                                 
     205                 :     /**                                                                         
     206                 :      * Offset unset                                                             
     207                 :      *                                                                          
     208                 :      * @param string $offset Name of the offset                                 
     209                 :      *                                                                          
     210                 :      * @return void                                                             
     211                 :      */                                                                         
     212                 :     public function offsetUnset($offset)                                        
     213                 :     {                                                                           
     214               1 :         unset($this->parameters[$this->prefixParameter($offset)]);              
     215               1 :     }                                                                           
     216                 :                                                                                 
     217                 :     /**                                                                         
     218                 :      * Count                                                                    
     219                 :      *                                                                          
     220                 :      * @return int Amount of parameters                                         
     221                 :      */                                                                         
     222                 :     public function count()                                                     
     223                 :     {                                                                           
     224               2 :         return count($this->parameters);                                        
     225                 :     }                                                                           
     226                 :                                                                                 
     227                 :     /**                                                                         
     228                 :      * Get iterator                                                             
     229                 :      *                                                                          
     230                 :      * @return ArrayIterator Iterator for self::$parameters                     
     231                 :      */                                                                         
     232                 :     public function getIterator()                                               
     233                 :     {                                                                           
     234               1 :         return new ArrayIterator($this->parameters);                            
     235                 :     }                                                                           
     236                 :                                                                                 
     237                 :     /**                                                                         
     238                 :      * Prefix parameter                                                         
     239                 :      *                                                                          
     240                 :      * Prefixes a parameter name with oauth_ if it is a valid oauth paramter    
     241                 :      *                                                                          
     242                 :      * @param string $param Name of the parameter                               
     243                 :      *                                                                          
     244                 :      * @return string Prefix parameter                                          
     245                 :      */                                                                         
     246                 :     protected function prefixParameter($param)                                  
     247                 :     {                                                                           
     248              32 :         if (in_array($param, self::$oauthParams)) {                             
     249               7 :             $param = 'oauth_' . $param;                                         
     250               7 :         }                                                                       
     251                 :                                                                                 
     252              32 :         return $param;                                                          
     253                 :     }                                                                           
     254                 :                                                                                 
     255                 : }                                                                               
     256                 :                                                                                 
     257                 : ?>                                                                              

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.