PHPIDS
Current file: /home/lstrojny/Projekte/php-ids/trunk/lib/IDS/Event.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 8 / 8
100.00 %100.00%
100.00% 36 / 36
 
IDS_Event
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 8 / 8
100.00 %100.00%
100.00% 36 / 36
 public function __construct($name, $value, array $filters)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 17 / 17
 public function getName()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
 public function getValue()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
 public function getImpact()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 7 / 7
 public function getTags()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 7 / 7
 public function getFilters()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
 public function count()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
 public function getIterator()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1


       1                 : <?php                                                                           
       2                 :                                                                                 
       3                 : /**                                                                             
       4                 :  * PHPIDS                                                                       
       5                 :  *                                                                              
       6                 :  * Requirements: PHP5, SimpleXML                                                
       7                 :  *                                                                              
       8                 :  * Copyright (c) 2008 PHPIDS group (http://php-ids.org)                         
       9                 :  *                                                                              
      10                 :  * PHPIDS is free software; you can redistribute it and/or modify               
      11                 :  * it under the terms of the GNU Lesser General Public License as published by  
      12                 :  * the Free Software Foundation, version 3 of the License, or                   
      13                 :  * (at your option) any later version.                                          
      14                 :  *                                                                              
      15                 :  * PHPIDS is distributed in the hope that it will be useful,                    
      16                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of               
      17                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                 
      18                 :  * GNU Lesser General Public License for more details.                          
      19                 :  *                                                                              
      20                 :  * You should have received a copy of the GNU Lesser General Public License     
      21                 :  * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.               
      22                 :  *                                                                              
      23                 :  * PHP version 5.1.6+                                                           
      24                 :  *                                                                              
      25                 :  * @category Security                                                           
      26                 :  * @package  PHPIDS                                                             
      27                 :  * @author   Mario Heiderich <mario.heiderich@gmail.com>                        
      28                 :  * @author   Christian Matthies <ch0012@gmail.com>                              
      29                 :  * @author   Lars Strojny <lars@strojny.net>                                    
      30                 :  * @license  http://www.gnu.org/licenses/lgpl.html LGPL                         
      31                 :  * @link     http://php-ids.org/                                                
      32                 :  */                                                                             
      33                 :                                                                                 
      34                 : /**                                                                             
      35                 :  * PHPIDS event object                                                          
      36                 :  *                                                                              
      37                 :  * This class represents a certain event that occured while applying the filters
      38                 :  * to the supplied data. It aggregates a bunch of IDS_Filter implementations and
      39                 :  * is a assembled in IDS_Report.                                                
      40                 :  *                                                                              
      41                 :  * Note that this class implements both Countable and IteratorAggregate         
      42                 :  *                                                                              
      43                 :  * @category  Security                                                          
      44                 :  * @package   PHPIDS                                                            
      45                 :  * @author    Christian Matthies <ch0012@gmail.com>                             
      46                 :  * @author    Mario Heiderich <mario.heiderich@gmail.com>                       
      47                 :  * @author    Lars Strojny <lars@strojny.net>                                   
      48                 :  * @copyright 2007 The PHPIDS Group                                             
      49                 :  * @license   http://www.gnu.org/licenses/lgpl.html LGPL                        
      50                 :  * @version   Release: $Id:Event.php 517 2007-09-15 15:04:13Z mario $           
      51                 :  * @link      http://php-ids.org/                                               
      52                 :  */                                                                             
      53                 : class IDS_Event implements Countable, IteratorAggregate                         
      54                 : {                                                                               
      55                 :                                                                                 
      56                 :     /**                                                                         
      57                 :      * Event name                                                               
      58                 :      *                                                                          
      59                 :      * @var scalar                                                              
      60                 :      */                                                                         
      61                 :     protected $name = null;                                                     
      62                 :                                                                                 
      63                 :     /**                                                                         
      64                 :      * Value of the event                                                       
      65                 :      *                                                                          
      66                 :      * @var scalar                                                              
      67                 :      */                                                                         
      68                 :     protected $value = null;                                                    
      69                 :                                                                                 
      70                 :     /**                                                                         
      71                 :      * List of filter objects                                                   
      72                 :      *                                                                          
      73                 :      * Filter objects in this array are those that matched the events value     
      74                 :      *                                                                          
      75                 :      * @var array                                                               
      76                 :      */                                                                         
      77                 :     protected $filters = array();                                               
      78                 :                                                                                 
      79                 :     /**                                                                         
      80                 :      * Calculated impact                                                        
      81                 :      *                                                                          
      82                 :      * Total impact of the event                                                
      83                 :      *                                                                          
      84                 :      * @var integer                                                             
      85                 :      */                                                                         
      86                 :     protected $impact = 0;                                                      
      87                 :                                                                                 
      88                 :     /**                                                                         
      89                 :      * Affecte tags                                                             
      90                 :      *                                                                          
      91                 :      * @var array                                                               
      92                 :      */                                                                         
      93                 :     protected $tags = array();                                                  
      94                 :                                                                                 
      95                 :     /**                                                                         
      96                 :      * Constructor                                                              
      97                 :      *                                                                          
      98                 :      * Fills event properties                                                   
      99                 :      *                                                                          
     100                 :      * @param scalar $name    the event name                                    
     101                 :      * @param scalar $value   the event value                                   
     102                 :      * @param array  $filters the corresponding filters                         
     103                 :      *                                                                          
     104                 :      * @return void                                                             
     105                 :      */                                                                         
     106                 :     public function __construct($name, $value, Array $filters)                  
     107                 :     {                                                                           
     108              58 :         if (!is_scalar($name)) {                                                
     109               1 :             throw new InvalidArgumentException(                                 
     110               1 :                 'Expected $name to be a scalar,' . gettype($name) . ' given'    
     111               1 :             );                                                                  
     112                 :         }                                                                       
     113                 :                                                                                 
     114              58 :         if (!is_scalar($value)) {                                               
     115               1 :             throw new InvalidArgumentException('                                
     116               1 :                 Expected $value to be a scalar,' . gettype($value) . ' given'   
     117               1 :             );                                                                  
     118                 :         }                                                                       
     119                 :                                                                                 
     120              58 :         $this->name  = $name;                                                   
     121              58 :         $this->value = $value;                                                  
     122                 :                                                                                 
     123              58 :         foreach ($filters as $filter) {                                         
     124              58 :             if (!$filter instanceof IDS_Filter) {                               
     125               1 :                 throw new InvalidArgumentException(                             
     126                 :                     'Filter must be derived from IDS_Filter'                    
     127               1 :                 );                                                              
     128                 :             }                                                                   
     129                 :                                                                                 
     130              58 :             $this->filters[] = $filter;                                         
     131              58 :         }                                                                       
     132              58 :     }                                                                           
     133                 :                                                                                 
     134                 :     /**                                                                         
     135                 :      * Returns event name                                                       
     136                 :      *                                                                          
     137                 :      * The name of the event usually is the key of the variable that was        
     138                 :      * considered to be malicious                                               
     139                 :      *                                                                          
     140                 :      * @return scalar                                                           
     141                 :      */                                                                         
     142                 :     public function getName()                                                   
     143                 :     {                                                                           
     144              53 :         return $this->name;                                                     
     145                 :     }                                                                           
     146                 :                                                                                 
     147                 :     /**                                                                         
     148                 :      * Returns event value                                                      
     149                 :      *                                                                          
     150                 :      * @return scalar                                                           
     151                 :      */                                                                         
     152                 :     public function getValue()                                                  
     153                 :     {                                                                           
     154               2 :         return $this->value;                                                    
     155                 :     }                                                                           
     156                 :                                                                                 
     157                 :     /**                                                                         
     158                 :      * Returns calculated impact                                                
     159                 :      *                                                                          
     160                 :      * @return integer                                                          
     161                 :      */                                                                         
     162                 :     public function getImpact()                                                 
     163                 :     {                                                                           
     164              35 :         if (!$this->impact) {                                                   
     165              35 :             $this->impact = 0;                                                  
     166              35 :             foreach ($this->filters as $filter) {                               
     167              35 :                 $this->impact += $filter->getImpact();                          
     168              35 :             }                                                                   
     169              35 :         }                                                                       
     170                 :                                                                                 
     171              35 :         return $this->impact;                                                   
     172                 :     }                                                                           
     173                 :                                                                                 
     174                 :     /**                                                                         
     175                 :      * Returns affected tags                                                    
     176                 :      *                                                                          
     177                 :      * @return array                                                            
     178                 :      */                                                                         
     179                 :     public function getTags()                                                   
     180                 :     {                                                                           
     181               4 :         $filters = $this->getFilters();                                         
     182                 :                                                                                 
     183               4 :         foreach ($filters as $filter) {                                         
     184               4 :             $this->tags = array_merge($this->tags,                              
     185               4 :                                       $filter->getTags());                      
     186               4 :         }                                                                       
     187                 :                                                                                 
     188               4 :         $this->tags = array_values(array_unique($this->tags));                  
     189                 :                                                                                 
     190               4 :         return $this->tags;                                                     
     191                 :     }                                                                           
     192                 :                                                                                 
     193                 :     /**                                                                         
     194                 :      * Returns list of filter objects                                           
     195                 :      *                                                                          
     196                 :      * @return array                                                            
     197                 :      */                                                                         
     198                 :     public function getFilters()                                                
     199                 :     {                                                                           
     200               9 :         return $this->filters;                                                  
     201                 :     }                                                                           
     202                 :                                                                                 
     203                 :     /**                                                                         
     204                 :      * Returns number of filters                                                
     205                 :      *                                                                          
     206                 :      * To implement interface Countable this returns the number of filters      
     207                 :      * appended.                                                                
     208                 :      *                                                                          
     209                 :      * @return integer                                                          
     210                 :      */                                                                         
     211                 :     public function count()                                                     
     212                 :     {                                                                           
     213               2 :         return count($this->getFilters());                                      
     214                 :     }                                                                           
     215                 :                                                                                 
     216                 :     /**                                                                         
     217                 :      * IteratorAggregate iterator getter                                        
     218                 :      *                                                                          
     219                 :      * Returns an iterator to iterate over the appended filters.                
     220                 :      *                                                                          
     221                 :      * @return Iterator|IteratorAggregate                                       
     222                 :      */                                                                         
     223                 :     public function getIterator()                                               
     224                 :     {                                                                           
     225               3 :         return new ArrayObject($this->getFilters());                            
     226                 :     }                                                                           
     227                 : }                                                                               
     228                 :                                                                                 
     229                 : /*                                                                              
     230                 :  * Local variables:                                                             
     231                 :  * tab-width: 4                                                                 
     232                 :  * c-basic-offset: 4                                                            
     233                 :  * End:                                                                         
     234                 :  */                                                                             

Generated by PHPUnit 3.3.1 and Xdebug 2.1.0-dev at Mon Dec 22 13:57:42 CET 2008.