Resource.php
Current file: /Users/kevin/code/twilio-php/Services/Twilio/Resource.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00% 0 / 1
90.00% 9 / 10 CRAP
96.30% 26 / 27
Services_Twilio_Resource
0.00% 0 / 1
90.00% 9 / 10 13
96.30% 26 / 27
 __construct(Services_Twilio_DataProxy $proxy)
100.00% 1 / 1 1
100.00% 5 / 5
 init()
100.00% 1 / 1 1
100.00% 1 / 1
 retrieveData($path, array $params = array()
100.00% 1 / 1 1
100.00% 1 / 1
 deleteData($path, array $params = array()
100.00% 1 / 1 1
100.00% 1 / 1
 createData($path, array $params = array()
100.00% 1 / 1 1
100.00% 1 / 1
 getSubresources($name = null)
0.00% 0 / 1 3.07
80.00% 4 / 5
 addSubresource($name, Services_Twilio_Resource $res)
100.00% 1 / 1 1
100.00% 2 / 2
 setupSubresources()
100.00% 1 / 1 2
100.00% 6 / 6
 decamelize($word)
100.00% 1 / 1 1
100.00% 4 / 4
 camelize($word)
100.00% 1 / 1 1
100.00% 1 / 1


       1                 : <?php                                                                          
       2                 :                                                                                
       3                 : /**                                                                            
       4                 :  * Abstraction of a Twilio resource.                                           
       5                 :  *                                                                             
       6                 :  * @category Services                                                          
       7                 :  * @package  Services_Twilio                                                   
       8                 :  * @author   Neuman Vong <neuman@twilio.com>                                   
       9                 :  * @license  http://creativecommons.org/licenses/MIT/ MIT                      
      10                 :  * @link     http://pear.php.net/package/Services_Twilio                       
      11                 :  */                                                                            
      12                 : abstract class Services_Twilio_Resource                                        
      13                 :     implements Services_Twilio_DataProxy                                       
      14                 : {                                                                              
      15                 :     protected $name;                                                           
      16                 :     protected $proxy;                                                          
      17                 :     protected $subresources;                                                   
      18                 :                                                                                
      19                 :     public function __construct(Services_Twilio_DataProxy $proxy)              
      20                 :     {                                                                          
      21              27 :         $this->subresources = array();                                         
      22              27 :         $this->proxy = $proxy;                                                 
      23              27 :         $this->name = get_class($this);                                        
      24              27 :         $this->init();                                                         
      25              27 :     }                                                                          
      26                 :                                                                                
      27                 :     protected function init()                                                  
      28                 :     {                                                                          
      29                 :         // Left empty for derived classes to implement                         
      30              27 :     }                                                                          
      31                 :                                                                                
      32                 :     public function retrieveData($path, array $params = array())               
      33                 :     {                                                                          
      34              12 :         return $this->proxy->retrieveData($path, $params);                     
      35                 :     }                                                                          
      36                 :                                                                                
      37                 :     public function deleteData($path, array $params = array())                 
      38                 :     {                                                                          
      39               1 :         return $this->proxy->deleteData($path, $params);                       
      40                 :     }                                                                          
      41                 :                                                                                
      42                 :     public function createData($path, array $params = array())                 
      43                 :     {                                                                          
      44              10 :         return $this->proxy->createData($path, $params);                       
      45                 :     }                                                                          
      46                 :                                                                                
      47                 :     public function getSubresources($name = null)                              
      48                 :     {                                                                          
      49              25 :         if (isset($name)) {                                                    
      50              25 :             return isset($this->subresources[$name])                           
      51              25 :                 ? $this->subresources[$name]                                   
      52              25 :                 : null;                                                        
      53                 :         }                                                                      
      54               0 :         return $this->subresources;                                            
      55                 :     }                                                                          
      56                 :                                                                                
      57                 :     public function addSubresource($name, Services_Twilio_Resource $res)       
      58                 :     {                                                                          
      59              27 :         $this->subresources[$name] = $res;                                     
      60              27 :     }                                                                          
      61                 :                                                                                
      62                 :     protected function setupSubresources()                                     
      63                 :     {                                                                          
      64              27 :         foreach (func_get_args() as $name) {                                   
      65              27 :             $constantized = ucfirst(Services_Twilio_Resource::camelize($name));
      66              27 :             $type = "Services_Twilio_Rest_" . $constantized;                   
      67              27 :             $this->addSubresource($name, new $type($this));                    
      68              27 :         }                                                                      
      69              27 :     }                                                                          
      70                 :                                                                                
      71                 :     public static function decamelize($word)                                   
      72                 :     {                                                                          
      73              27 :         return preg_replace(                                                   
      74              27 :             '/(^|[a-z])([A-Z])/e',                                             
      75              27 :             'strtolower(strlen("\\1") ? "\\1_\\2" : "\\2")',                   
      76                 :             $word                                                              
      77              27 :         );                                                                     
      78                 :     }                                                                          
      79                 :                                                                                
      80                 :     public static function camelize($word)                                     
      81                 :     {                                                                          
      82              27 :         return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);    
      83                 :     }                                                                          
      84                 : }                                                                              
      85                 :                                                                                

Generated by PHP_CodeCoverage 1.1.2 using PHP 5.3.13 and PHPUnit 3.6.11 at Mon Jun 4 22:46:14 PDT 2012.