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

CheckException::getNestedDebug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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