DrWatson::help()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace BSP\DrWatson;
5
6
use MyCLabs\Enum\Enum;
7
use Throwable;
8
9
/**
10
 * Class DrWatson
11
 * @package BSP\DrWatson
12
 *
13
 * Add type, suspect and help to \Exception, in order to have easier times when debugging.
14
 */
15
class DrWatson extends \Exception
16
{
17
    /**
18
     * @var Enum
19
     *
20
     * You can use \BSP\DrWatson\ExceptionType or create your own Enum.
21
     * Please visit https://github.com/myclabs/php-enum to learn how.
22
     */
23
    private $type;
24
25
    /**
26
     * @var string
27
     *
28
     * This is a hint for developpers, should provide a fieldName, class::method, etc...
29
     * It should point out the best place to start investigation.
30
     */
31
    private $suspect;
32
33
    /**
34
     * @var string
35
     *
36
     * This message is a hint meant for developpers, explaining reasons for the exception. It should be deeper and
37
     * more precise than \BSP\DrWatson\DrWatson::$suspect, so do not hesitate to add explanation here, even if it's
38
     * long text.
39
     * The more details there is, the easier it will be to debug.
40
     */
41
    private $help;
42
43 1
    public function __construct(
44
        Enum $exceptionType,
45
        string $message = "",
46
        string $suspect = "",
47
        string $help = "",
48
        int $code = 0,
49
        Throwable $previous = null
50
    ) {
51 1
        parent::__construct($message, $code, $previous);
52 1
        $this->type = $exceptionType;
53 1
        $this->suspect = $suspect;
54 1
        $this->help = $help;
55 1
    }
56
57 1
    public function type(): Enum
58
    {
59 1
        return $this->type;
60
    }
61
62 1
    public function message(): string
63
    {
64 1
        return $this->message;
65
    }
66
67 1
    public function suspect(): string
68
    {
69 1
        return $this->suspect;
70
    }
71
72 1
    public function help(): string
73
    {
74 1
        return $this->help;
75
    }
76
77 1
    public function code(): int
78
    {
79 1
        return $this->code;
80
    }
81
}
82