Completed
Push — master ( df1a77...53322f )
by Dmitry
03:46
created

FormulaEngineException::fromException()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
ccs 4
cts 5
cp 0.8
rs 9.2
cc 4
eloc 9
nc 6
nop 3
crap 4.128
1
<?php
2
3
namespace hiqdev\php\billing\formula;
4
5
use Exception;
6
use hiqdev\php\billing\ExceptionInterface;
7
use Throwable;
8
9
/**
10
 * Class FormulaEngineException
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class FormulaEngineException extends Exception
15
{
16
    /**
17
     * @var string
18
     */
19
    private $formula;
20
21
    public static function fromException(Throwable $previous, string $formula, string $message = null): FormulaEngineException
22
    {
23
        if ($previous !== null) {
24
            if ($message !== null) {
25
                $message .= ': ';
26
            }
27
28 1
            $message .= $previous->getMessage();
29
        }
30 1
31 1
        $exception = new static($message, 0, $previous);
32
        if ($formula !== null) {
33
            $exception->formula = $formula;
34
        }
35 1
36
        return $exception;
37
    }
38 1
39 1
    public static function create(string $formula, string $message)
40 1
    {
41
        $exception = new static($message);
42
43 1
        if ($formula !== null) {
44
            $exception->formula = $formula;
45
        }
46 1
47
        return $exception;
48 1
    }
49
50 1
    public function getFormula(): ?string
51 1
    {
52
        return $this->formula;
53
    }
54
}
55