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

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