PHPIDS
Current file: /home/mario/workspace/php-ids.org/trunk/lib/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
50.00 %50.00%
50.00% 1 / 2
53.85 %53.85%
53.85% 7 / 13
 
HTMLPurifier_AttrDef_CSS_ImportantDecorator
100.00 %100.00%
100.00% 1 / 1
50.00 %50.00%
50.00% 1 / 2
53.85 %53.85%
53.85% 7 / 13
 public function __construct($def, $allow = false)
0.00 %0.00%
0.00% 0 / 1
100.00 %100.00%
100.00% 0 / 0
 public function validate($string, $config, $context)
100.00 %100.00%
100.00% 1 / 1
50.00 %50.00%
50.00% 6 / 12


       1                 : <?php                                                                         
       2                 :                                                                               
       3                 : /**                                                                           
       4                 :  * Decorator which enables !important to be used in CSS values.               
       5                 :  */                                                                           
       6               1 : class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef
       7                 : {                                                                             
       8                 :     protected $def, $allow;                                                   
       9                 :                                                                               
      10                 :     /**                                                                       
      11                 :      * @param $def Definition to wrap                                         
      12                 :      * @param $allow Whether or not to allow !important                       
      13                 :      */                                                                       
      14                 :     public function __construct($def, $allow = false) {                       
      15                 :         $this->def = $def;                                                    
      16                 :         $this->allow = $allow;                                                
      17                 :     }                                                                         
      18                 :     /**                                                                       
      19                 :      * Intercepts and removes !important if necessary                         
      20                 :      */                                                                       
      21                 :     public function validate($string, $config, $context) {                    
      22                 :         // test for ! and important tokens                                    
      23               2 :         $string = trim($string);                                              
      24               2 :         $is_important = false;                                                
      25                 :         // :TODO: optimization: test directly for !important and ! important  
      26               2 :         if (strlen($string) >= 9 && substr($string, -9) === 'important') {    
      27               0 :             $temp = rtrim(substr($string, 0, -9));                            
      28                 :             // use a temp, because we might want to restore important         
      29               0 :             if (strlen($temp) >= 1 && substr($temp, -1) === '!') {            
      30               0 :                 $string = rtrim(substr($temp, 0, -1));                        
      31               0 :                 $is_important = true;                                         
      32               0 :             }                                                                 
      33               0 :         }                                                                     
      34               2 :         $string = $this->def->validate($string, $config, $context);           
      35               2 :         if ($this->allow && $is_important) $string .= ' !important';          
      36               2 :         return $string;                                                       
      37                 :     }                                                                         
      38                 : }                                                                             

Generated by PHPUnit 3.3.1 and Xdebug 2.0.2 at Thu Sep 25 18:42:10 CEST 2008.