Current file: /home/greg/workspace/PHPDS-dev-trunk/PHPDevShell/stable/trunk/includes/PHPDS_exception.class.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
42.86%42.86%
42.86% 3 / 7
25.00%25.00%
25.00% 3 / 12 CRAP
23.38%23.38%
23.38% 18 / 77
 
PHPDS_exception
0.00%0.00%
0.00% 0 / 1
33.33%33.33%
33.33% 2 / 6
77.78%77.78%
77.78% 14 / 18
 __construct($message = "", $code = 0, $previous = null)
100.00%100.00%
100.00% 1 / 1 5
100.00%100.00%
100.00% 13 / 13
 getignoreLines()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getExtendedMessage()
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 1 / 1
 getExtendedTrace()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 1
 hasCauses()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getCauses()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
PHPDS_fatalError
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 6
 __construct($message = "", $code = 0, $previous = null)
0.00%0.00%
0.00% 0 / 1 30
0.00%0.00%
0.00% 0 / 6
PHPDS_databaseException
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 2
0.00%0.00%
0.00% 0 / 43
 hasCauses()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 6
 getCauses()
0.00%0.00%
0.00% 0 / 1 110
0.00%0.00%
0.00% 0 / 37
PHPDS_securityException
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 0 / 0
PHPDS_securityException403
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 0 / 0
PHPDS_pageException404
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 0 / 0
PHPDS_sprintfnException
0.00%0.00%
0.00% 0 / 1
33.33%33.33%
33.33% 1 / 3
40.00%40.00%
40.00% 4 / 10
 __construct($message = "", $code = 0, $previous = null)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 4 / 4
 hasCauses()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getCauses()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 5


       1                 : <?php                                                                                                                                                                                             
       2                 : /**                                                                                                                                                                                               
       3                 :  * PHPDevShell is a RAD Framework aimed at developing administrative applications.                                                                                                                
       4                 :  *                                                                                                                                                                                                
       5                 :  * @package PHPDevShell                                                                                                                                                                           
       6                 :  * @link http://www.phpdevshell.org                                                                                                                                                               
       7                 :  * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved.                                                                                                                             
       8                 :  * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html                                                                                    
       9                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                                                                             
      10                 :  *                                                                                                                                                                                                
      11                 :  * Copyright notice: See readme/notice                                                                                                                                                            
      12                 :  * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell.                                                         
      13                 :  */                                                                                                                                                                                               
      14                 : /**                                                                                                                                                                                               
      15                 :  * Exception extenstion.                                                                                                                                                                          
      16                 :  */                                                                                                                                                                                               
      17                 : class PHPDS_exception extends Exception                                                                                                                                                           
      18                 : {                                                                                                                                                                                                 
      19                 :     protected $ignoreLines = 0;                                                                                                                                                                   
      20                 :     protected $extendedMessage = '';                                                                                                                                                              
      21                 :                                                                                                                                                                                                   
      22                 :     public function __construct($message = "", $code = 0, $previous = null)                                                                                                                       
      23                 :     {                                                                                                                                                                                             
      24              23 :         if (is_a($previous, 'Exception')) {                                                                                                                                                       
      25              21 :             $this->file = $previous->getFile();                                                                                                                                                   
      26              21 :             $this->line = $previous->getLine();                                                                                                                                                   
      27              21 :             $this->message .= $previous->getMessage();                                                                                                                                            
      28              21 :             $this->trace = $previous->getTrace();                                                                                                                                                 
      29              21 :             $this->code = $previous->getCode();                                                                                                                                                   
      30              21 :             if (empty($this->code)) $this->code = $code;                                                                                                                                          
      31              21 :             if (is_a($previous, 'PHPDS_exception')) $this->extendedMessage .= $previous->getExtendedMessage();                                                                                    
      32              21 :             if ($message) $this->extendedMessage .= $message;                                                                                                                                     
      33              21 :         } else {                                                                                                                                                                                  
      34               2 :             $this->message = $message;                                                                                                                                                            
      35               2 :             $this->code = $code;                                                                                                                                                                  
      36                 :         }                                                                                                                                                                                         
      37                 :                                                                                                                                                                                                   
      38                 :         /*$this->ignoreLines = $code;                                                                                                                                                             
      39                 :         $this->code = 0;*/                                                                                                                                                                        
      40              23 :     }                                                                                                                                                                                             
      41                 :                                                                                                                                                                                                   
      42                 :     public function getignoreLines()                                                                                                                                                              
      43                 :     {                                                                                                                                                                                             
      44               0 :         return $this->ignoreLines;                                                                                                                                                                
      45                 :     }                                                                                                                                                                                             
      46                 :                                                                                                                                                                                                   
      47                 :     public function getExtendedMessage()                                                                                                                                                          
      48                 :     {                                                                                                                                                                                             
      49              20 :         return $this->extendedMessage;                                                                                                                                                            
      50                 :     }                                                                                                                                                                                             
      51                 :                                                                                                                                                                                                   
      52                 :     public function getExtendedTrace()                                                                                                                                                            
      53                 :     {                                                                                                                                                                                             
      54               0 :         return empty($this->trace) ? $this->getTrace() : $this->trace;                                                                                                                            
      55                 :     }                                                                                                                                                                                             
      56                 :                                                                                                                                                                                                   
      57                 :     /**                                                                                                                                                                                           
      58                 :      * some Exception may choose to display some possible cause for the error, to help tracking down the error                                                                                    
      59                 :      */                                                                                                                                                                                           
      60                 :     public function hasCauses()                                                                                                                                                                   
      61                 :     {                                                                                                                                                                                             
      62               0 :         return false;                                                                                                                                                                             
      63                 :     }                                                                                                                                                                                             
      64                 :                                                                                                                                                                                                   
      65                 :     /**                                                                                                                                                                                           
      66                 :      *  returns a special message and a list of possible causes                                                                                                                                   
      67                 :      */                                                                                                                                                                                           
      68                 :     public function getCauses()                                                                                                                                                                   
      69                 :     {                                                                                                                                                                                             
      70               0 :         return null;                                                                                                                                                                              
      71                 :     }                                                                                                                                                                                             
      72                 : }                                                                                                                                                                                                 
      73                 :                                                                                                                                                                                                   
      74                 : class PHPDS_fatalError extends PHPDS_exception                                                                                                                                                    
      75                 : {                                                                                                                                                                                                 
      76                 :     public function __construct($message = "", $code = 0, $previous = null)                                                                                                                       
      77                 :     {                                                                                                                                                                                             
      78               0 :         $error = error_get_last();                                                                                                                                                                
      79                 :                                                                                                                                                                                                   
      80               0 :         if (isset($error['message'])) $this->message = $error['message'];                                                                                                                         
      81               0 :         if (isset($error['type'])) $this->code = $error['type'];                                                                                                                                  
      82               0 :         if (isset($error['file'])) $this->file = $error['file'];                                                                                                                                  
      83               0 :         if (isset($error['line'])) $this->line = $error['line'];                                                                                                                                  
      84                 :                                                                                                                                                                                                   
      85                 :         //$this->ignoreLines = 2;                                                                                                                                                                 
      86               0 :     }                                                                                                                                                                                             
      87                 : }                                                                                                                                                                                                 
      88                 :                                                                                                                                                                                                   
      89                 : class PHPDS_databaseException extends PHPDS_exception                                                                                                                                             
      90                 : {                                                                                                                                                                                                 
      91                 :                                                                                                                                                                                                   
      92                 :     public function hasCauses()                                                                                                                                                                   
      93                 :     {                                                                                                                                                                                             
      94               0 :         return in_array($this->getCode(), array(                                                                                                                                                  
      95               0 :             1045, // access denied                                                                                                                                                                
      96               0 :             0,  // unknown error                                                                                                                                                                  
      97               0 :             1049,  // unknown database                                                                                                                                                            
      98               0 :             2002,                                                                                                                                                                                 
      99                 :             1146 // table doesn't exist                                                                                                                                                           
     100               0 :             ));                                                                                                                                                                                   
     101                 :     }                                                                                                                                                                                             
     102                 :                                                                                                                                                                                                   
     103                 :     public function getCauses()                                                                                                                                                                   
     104                 :     {                                                                                                                                                                                             
     105               0 :         switch ($this->getCode()) {                                                                                                                                                               
     106               0 :             case 1045: $special = 'db_access_denied'; break;                                                                                                                                      
     107               0 :             case 0: $special = 'db_unknown'; break;                                                                                                                                               
     108               0 :             case 1049: $special = 'db_unknown'; break;                                                                                                                                            
     109               0 :             case 2002: $special = 'db_silent'; break;                                                                                                                                             
     110               0 :             case 1146: $special = 'db_noexist'; break;                                                                                                                                            
     111               0 :         }                                                                                                                                                                                         
     112                 :                                                                                                                                                                                                   
     113                 :         $phpds_not_installed = array(                                                                                                                                                             
     114               0 :             '<div class="warning">PHPDevShell have a database error, did you install yet?<div>',                                                                                                  
     115                 :             'If you didn\'t process the installation procedure, you should <a href="other/service/index.php">run the installer</a> now.'                                                          
     116               0 :         );                                                                                                                                                                                        
     117                 :         $db_wrong_cred = array(                                                                                                                                                                   
     118               0 :             '<div class="warning">Possibly wrong credentials have been given in the configuration file.</div>',                                                                                   
     119                 :             'Please check the content of your configuration file(s).'                                                                                                                             
     120               0 :         );                                                                                                                                                                                        
     121                 :         $db_wrong_dbname = array(                                                                                                                                                                 
     122               0 :             '<div class="warning">Possibly wrong database name has been given in the configuration file.<div>',                                                                                   
     123                 :             'Please check the content of your configuration file(s).'                                                                                                                             
     124               0 :         );                                                                                                                                                                                        
     125                 :         $db_denies = array(                                                                                                                                                                       
     126               0 :             '<div class="warning">The server wont accept the connection.</div>',                                                                                                                  
     127                 :             'Please check that the database server is up and running.'                                                                                                                            
     128               0 :         );                                                                                                                                                                                        
     129                 :                                                                                                                                                                                                   
     130                 :         switch ($special) {                                                                                                                                                                       
     131               0 :             case 'db_access_denied': $result = array(                                                                                                                                             
     132               0 :                 'Access to the database was not granted using the parameters set in the configuration file.',                                                                                     
     133               0 :                 array($phpds_not_installed, $db_wrong_cred, $db_denies)                                                                                                                           
     134               0 :             ); break;                                                                                                                                                                             
     135               0 :             case 'db_silent': $result = array(                                                                                                                                                    
     136               0 :                 'Unable to connect to the database.',                                                                                                                                             
     137               0 :                 array($db_wrong_cred, $db_denies)                                                                                                                                                 
     138               0 :             ); break;                                                                                                                                                                             
     139               0 :             case 'db_unknown': $result = array(                                                                                                                                                   
     140               0 :                 'The connection to the server is ok but the database is unknown.',                                                                                                                
     141               0 :                 array($phpds_not_installed, $db_wrong_dbname)                                                                                                                                     
     142               0 :             ); break;                                                                                                                                                                             
     143               0 :             case 'db_noexist': $result = array(                                                                                                                                                   
     144               0 :                 'The connection to the server is ok and the database is known but the table doesn\'t exists.',                                                                                    
     145               0 :                 array($phpds_not_installed, $db_wrong_dbname)                                                                                                                                     
     146               0 :             ); break;                                                                                                                                                                             
     147               0 :             default: $result = array(                                                                                                                                                             
     148               0 :                 'Unknown special case.',                                                                                                                                                          
     149               0 :                 array()                                                                                                                                                                           
     150               0 :             );                                                                                                                                                                                    
     151               0 :         }                                                                                                                                                                                         
     152               0 :         return $result;                                                                                                                                                                           
     153                 :     }                                                                                                                                                                                             
     154                 :                                                                                                                                                                                                   
     155                 : }                                                                                                                                                                                                 
     156                 :                                                                                                                                                                                                   
     157                 :                                                                                                                                                                                                   
     158                 : class PHPDS_securityException extends PHPDS_exception                                                                                                                                             
     159                 : {                                                                                                                                                                                                 
     160                 :     // Nothing required today.                                                                                                                                                                    
     161                 : }                                                                                                                                                                                                 
     162                 :                                                                                                                                                                                                   
     163                 : class PHPDS_securityException403 extends PHPDS_exception                                                                                                                                          
     164                 : {                                                                                                                                                                                                 
     165                 :     // Nothing required today.                                                                                                                                                                    
     166                 : }                                                                                                                                                                                                 
     167                 :                                                                                                                                                                                                   
     168                 : class PHPDS_pageException404 extends PHPDS_exception                                                                                                                                              
     169                 : {                                                                                                                                                                                                 
     170                 :     // Nothing required today.                                                                                                                                                                    
     171                 : }                                                                                                                                                                                                 
     172                 :                                                                                                                                                                                                   
     173                 :                                                                                                                                                                                                   
     174                 :                                                                                                                                                                                                   
     175                 : class PHPDS_sprintfnException extends PHPDS_exception                                                                                                                                             
     176                 : {                                                                                                                                                                                                 
     177                 :                                                                                                                                                                                                   
     178                 :     public function __construct($message = "", $code = 0, $previous = null) // CAUTION this declaration is NOT correct                                                                            
     179                 :     {                                                                                                                                                                                             
     180               1 :         $msg = '<p>The faulty string source is:<br /><pre class="ui-state-highlight ui-corner-all">'.htmlentities($message).'</pre><br />';                                                       
     181               1 :         if (!empty($code)) $msg .= 'The parameters were:<br /><tt>'.PU_dumpArray($code, null, true).'</tt></p>';                                                                                  
     182                 :                                                                                                                                                                                                   
     183               1 :         parent::__construct($msg, 0, $previous);                                                                                                                                                  
     184               1 :     }                                                                                                                                                                                             
     185                 :                                                                                                                                                                                                   
     186                 :     public function hasCauses()                                                                                                                                                                   
     187                 :     {                                                                                                                                                                                             
     188               0 :         return true;                                                                                                                                                                              
     189                 :     }                                                                                                                                                                                             
     190                 :                                                                                                                                                                                                   
     191                 :     public function getCauses()                                                                                                                                                                   
     192                 :     {                                                                                                                                                                                             
     193                 :         $result = array(                                                                                                                                                                          
     194               0 :             'Unable to build a string with <i>sprintfn</i>',                                                                                                                                      
     195                 :             array(                                                                                                                                                                                
     196               0 :                 array('Some template or theme file has altered a module which does comply to the given parameters.', 'Try a different theme or check for possible typos in the theme module list')
     197               0 :             )                                                                                                                                                                                     
     198               0 :         );                                                                                                                                                                                        
     199                 :                                                                                                                                                                                                   
     200               0 :         return $result;                                                                                                                                                                           
     201                 :     }                                                                                                                                                                                             
     202                 :                                                                                                                                                                                                   
     203                 : }                                                                                                                                                                                                 

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.6 and PHPUnit 3.5.14 at Mon Aug 8 22:35:38 PDT 2011.