FormulaEngineException::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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