LoggerConfigurable.php
Current file: /home/ihabunek/apache/log4php/src/main/php/LoggerConfigurable.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00% 0 / 1
12.50% 1 / 8 CRAP
50.00% 22 / 44
LoggerConfigurable
0.00% 0 / 1
12.50% 1 / 8 53.12
50.00% 22 / 44
 setBoolean($property, $value)
100.00% 1 / 1 2
100.00% 5 / 5
 setInteger($property, $value)
0.00% 0 / 1 6
0.00% 0 / 5
 setLevel($property, $value)
0.00% 0 / 1 2.26
60.00% 3 / 5
 setPositiveInteger($property, $value)
0.00% 0 / 1 2.26
60.00% 3 / 5
 setFileSize($property, $value)
0.00% 0 / 1 2.26
60.00% 3 / 5
 setNumeric($property, $value)
0.00% 0 / 1 6
0.00% 0 / 5
 setString($property, $value, $nullable = false)
0.00% 0 / 1 4.32
72.73% 8 / 11
 warn($message)
0.00% 0 / 1 2
0.00% 0 / 3


       1                 : <?php                                                                                                                                 
       2                 : /**                                                                                                                                   
       3                 : * Licensed to the Apache Software Foundation (ASF) under one or more                                                                  
       4                 : * contributor license agreements. See the NOTICE file distributed with                                                                
       5                 : * this work for additional information regarding copyright ownership.                                                                 
       6                 : * The ASF licenses this file to You under the Apache License, Version 2.0                                                             
       7                 : * (the "License"); you may not use this file except in compliance with                                                                
       8                 : * the License. You may obtain a copy of the License at                                                                                
       9                 : *                                                                                                                                     
      10                 : *       http://www.apache.org/licenses/LICENSE-2.0                                                                                    
      11                 : *                                                                                                                                     
      12                 : * Unless required by applicable law or agreed to in writing, software                                                                 
      13                 : * distributed under the License is distributed on an "AS IS" BASIS,                                                                   
      14                 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                                                            
      15                 : * See the License for the specific language governing permissions and                                                                 
      16                 : * limitations under the License.                                                                                                      
      17                 : *                                                                                                                                     
      18                 : * @package log4php                                                                                                                    
      19                 : */                                                                                                                                    
      20                 :                                                                                                                                       
      21                 : /**                                                                                                                                   
      22                 :  * A base class from which all classes which have configurable properties are                                                         
      23                 :  * extended. Provides a generic setter with integrated validation.                                                                    
      24                 :  *                                                                                                                                    
      25                 :  * @package log4php                                                                                                                   
      26                 :  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0                                                    
      27                 :  * @version $Revision $                                                                                                               
      28                 :  * @since 2.2                                                                                                                         
      29                 :  */                                                                                                                                   
      30                 : abstract class LoggerConfigurable {                                                                                                   
      31                 :                                                                                                                                       
      32                 :     /** Setter function for boolean type. */                                                                                          
      33                 :     protected function setBoolean($property, $value) {                                                                                
      34                 :         try {                                                                                                                         
      35              23 :             $this->$property = LoggerOptionConverter::toBooleanEx($value);                                                            
      36              23 :         } catch (Exception $ex) {                                                                                                     
      37               1 :             $value = var_export($value, true);                                                                                        
      38               1 :             $this->warn("Invalid value given for '$property' property: [$value]. Expected a boolean value. Property not changed.");   
      39                 :         }                                                                                                                             
      40              22 :     }                                                                                                                                 
      41                 :                                                                                                                                       
      42                 :     /** Setter function for integer type. */                                                                                          
      43                 :     protected function setInteger($property, $value) {                                                                                
      44                 :         try {                                                                                                                         
      45               0 :             $this->$property = LoggerOptionConverter::toIntegerEx($value);                                                            
      46               0 :         } catch (Exception $ex) {                                                                                                     
      47               0 :             $value = var_export($value, true);                                                                                        
      48               0 :             $this->warn("Invalid value given for '$property' property: [$value]. Expected an integer. Property not changed.");        
      49                 :         }                                                                                                                             
      50               0 :     }                                                                                                                                 
      51                 :                                                                                                                                       
      52                 :     /** Setter function for LoggerLevel values. */                                                                                    
      53                 :     protected function setLevel($property, $value) {                                                                                  
      54                 :         try {                                                                                                                         
      55              15 :             $this->$property = LoggerOptionConverter::toLevelEx($value);                                                              
      56              15 :         } catch (Exception $ex) {                                                                                                     
      57               0 :             $value = var_export($value, true);                                                                                        
      58               0 :             $this->warn("Invalid value given for '$property' property: [$value]. Expected a level value. Property not changed.");     
      59                 :         }                                                                                                                             
      60              15 :     }                                                                                                                                 
      61                 :                                                                                                                                       
      62                 :     /** Setter function for integer type. */                                                                                          
      63                 :     protected function setPositiveInteger($property, $value) {                                                                        
      64                 :         try {                                                                                                                         
      65               4 :             $this->$property = LoggerOptionConverter::toPositiveIntegerEx($value);                                                    
      66               4 :         } catch (Exception $ex) {                                                                                                     
      67               0 :             $value = var_export($value, true);                                                                                        
      68               0 :             $this->warn("Invalid value given for '$property' property: [$value]. Expected a positive integer. Property not changed.");
      69                 :         }                                                                                                                             
      70               4 :     }                                                                                                                                 
      71                 :                                                                                                                                       
      72                 :     /** Setter for file size. */                                                                                                      
      73                 :     protected function setFileSize($property, $value) {                                                                               
      74                 :         try {                                                                                                                         
      75               3 :             $this->$property = LoggerOptionConverter::toFileSizeEx($value);                                                           
      76               3 :         } catch (Exception $ex) {                                                                                                     
      77               0 :             $value = var_export($value, true);                                                                                        
      78               0 :             $this->warn("Invalid value given for '$property' property: [$value]. Expected a file size value.  Property not changed.");
      79                 :         }                                                                                                                             
      80               3 :     }                                                                                                                                 
      81                 :                                                                                                                                       
      82                 :     /** Setter function for numeric type. */                                                                                          
      83                 :     protected function setNumeric($property, $value) {                                                                                
      84                 :         try {                                                                                                                         
      85               0 :             $this->$property = LoggerOptionConverter::toNumericEx($value);                                                            
      86               0 :         } catch (Exception $ex) {                                                                                                     
      87               0 :             $value = var_export($value, true);                                                                                        
      88               0 :             $this->warn("Invalid value given for '$property' property: [$value]. Expected a number. Property not changed.");          
      89                 :         }                                                                                                                             
      90               0 :     }                                                                                                                                 
      91                 :                                                                                                                                       
      92                 :     /** Setter function for string type. */                                                                                           
      93                 :     protected function setString($property, $value, $nullable = false) {                                                              
      94              25 :         if ($value === null) {                                                                                                        
      95               1 :             if($nullable) {                                                                                                           
      96               1 :                 $this->$property= null;                                                                                               
      97               1 :             } else {                                                                                                                  
      98               0 :                 $this->warn("Null value given for '$property' property. Expected a string. Property not changed.");                   
      99                 :             }                                                                                                                         
     100               1 :         } else {                                                                                                                      
     101                 :             try {                                                                                                                     
     102              24 :                 $this->$property = LoggerOptionConverter::toStringEx($value);                                                         
     103              24 :             } catch (Exception $ex) {                                                                                                 
     104               0 :                 $value = var_export($value, true);                                                                                    
     105               0 :                 $this->warn("Invalid value given for '$property' property: [$value]. Expected a string. Property not changed.");      
     106                 :             }                                                                                                                         
     107                 :         }                                                                                                                             
     108              25 :     }                                                                                                                                 
     109                 :                                                                                                                                       
     110                 :     /** Triggers a warning. */                                                                                                        
     111                 :     protected function warn($message) {                                                                                               
     112               0 :         $class = get_class($this);                                                                                                    
     113               0 :         trigger_error("log4php: $class: $message", E_USER_WARNING);                                                                   
     114               0 :     }                                                                                                                                 
     115                 : }                                                                                                                                     
     116                 :                                                                                                                                       
     117                 :                                                                                                                                       
     118                 :                                                                                                                                       

Generated by PHP_CodeCoverage 1.1.1 using PHP 5.3.3-7+squeeze3 and PHPUnit 3.6.3 at Sat Feb 18 22:32:39 GMT 2012.