AbstractException   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 72
ccs 14
cts 14
cp 1
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setCode() 0 5 3
A setLine() 0 5 3
A setMessage() 0 7 2
A setFile() 0 7 2
1
<?php
2
3
/**
4
 * Abstraction for all framework exceptions.
5
 */
6
7
namespace CryptoManana\Core\Abstractions\ErrorHandling;
8
9
use CryptoManana\Core\Interfaces\ErrorHandling\EditableExceptionInterface as EditableProperties;
10
use Exception as PhpException;
11
12
/**
13
 * Class AbstractException - Abstraction for all framework exceptions.
14
 *
15
 * @package CryptoManana\Core\Abstractions\ErrorHandling
16
 */
17
abstract class AbstractException extends PhpException implements EditableProperties
18
{
19
    /**
20
     * The default framework internal error code.
21
     */
22
    const INTERNAL_CODE = 0;
23
24
    /**
25
     * Get the default framework error code for this exception instance.
26
     *
27
     * @return int The exception's error code.
28
     */
29
    abstract public function getFrameworkErrorCode();
30
31
    /**
32
     * Change the exception's error message via fluent interface call.
33
     *
34
     * @param string|mixed $message Set a different error message.
35
     *
36
     * @return $this The exception object.
37
     */
38 16
    public function setMessage($message)
39
    {
40 16
        if (is_string($message)) {
41 16
            $this->message = $message;
42
        }
43
44 16
        return $this;
45
    }
46
47
    /**
48
     * Change the exception's error code via fluent interface call.
49
     *
50
     * @param int $code Set a different exception error code.
51
     *
52
     * @return $this The exception object.
53
     */
54 15
    public function setCode($code)
55
    {
56 15
        $this->code = is_int($code) && $code >= 0 ? $code : $this->code;
57
58 15
        return $this;
59
    }
60
61
    /**
62
     * Change the file location where the exception occurred via fluent interface call.
63
     *
64
     * @param string|mixed $file Set a different file path for the exception.
65
     *
66
     * @return $this The exception object.
67
     */
68 16
    public function setFile($file)
69
    {
70 16
        if (is_string($file)) {
71 16
            $this->file = $file;
72
        }
73
74 16
        return $this;
75
    }
76
77
    /**
78
     * Change the file location where the exception occurred via fluent interface call.
79
     *
80
     * @param int $line Set a different file line for the exception.
81
     *
82
     * @return $this The exception object.
83
     */
84 16
    public function setLine($line)
85
    {
86 16
        $this->line = is_int($line) && $line >= 1 ? $line : $this->line;
87
88 16
        return $this;
89
    }
90
}
91