Completed
Push — master ( 6dde3c...c34bb5 )
by Andrii
05:13
created

FormulaEngineException::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 2
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-2018, 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 ($previous !== null) {
31 1
            if ($message !== null) {
32
                $message .= ': ';
33
            }
34
35 1
            $message .= $previous->getMessage();
36
        }
37
38 1
        $exception = new static($message, 0, $previous);
39 1
        if ($formula !== null) {
40 1
            $exception->formula = $formula;
41
        }
42
43 1
        return $exception;
44
    }
45
46 1
    public static function create(string $formula, string $message)
47
    {
48 1
        $exception = new static($message);
49
50 1
        if ($formula !== null) {
51 1
            $exception->formula = $formula;
52
        }
53
54 1
        return $exception;
55
    }
56
57
    public function getFormula(): ?string
58
    {
59
        return $this->formula;
60
    }
61
}
62