Passed
Push — master ( 19a8ce...41e71a )
by Dmitry
10:01
created

CheckException   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 9
c 3
b 1
f 1
lcom 0
cbo 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
B getDebug() 0 17 5
A getNestedDebug() 0 4 1
1
<?php
2
3
namespace TonicHealthCheck\Check;
4
5
use Exception;
6
7
/**
8
 * Class CheckException
9
 */
10
class CheckException extends \Exception
11
{
12
    const EXCEPTION_NAME = 'healthCheck';
13
14
    /**
15
     * HttpCheckException constructor.
16
     *
17
     * @param string          $message
18
     * @param null|int        $code
19
     * @param null|\Exception $previous
20
     */
21
    public function __construct($message = '', $code = null, \Exception $previous = null)
22
    {
23
        if (0 === $code || null === $code) {
24
            $code = -1;
25
        }
26
        parent::__construct(static::EXCEPTION_NAME.': '.$message, $code, $previous);
27
    }
28
29
    /**
30
     * @param Exception $e
31
     * @return string
32
     */
33
    protected static function getDebug(Exception $e, $depth = -1)
34
    {
35
        $errorDebugMsg = sprintf (
36
            "ERROR CODE:%d\nERROR FILE:%s\nERROR MESSAGE:%sERROR TRACE:%s",
37
            $e->getCode (),
38
            $e->getFile (),
39
            $e->getMessage (),
40
            $e->getTraceAsString ()
41
        );
42
43
        if( ($depth ==-1 || $depth >0 ) && $e->getPrevious() instanceof Exception){
44
            $depth -= $depth>0?1:0;
45
            $errorDebugMsg = sprintf ('%s\n\nPRIVIOUS ERROR:\n', static::getDebug ($e->getPrevious()));
46
        }
47
48
        return $errorDebugMsg;
49
    }
50
51
    public function getNestedDebug($depth = -1)
52
    {
53
        return static::getDebug($this, $depth);
54
    }
55
}
56