FormulaEngineException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 32
ccs 10
cts 13
cp 0.7692
rs 10
c 3
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormula() 0 3 1
A create() 0 6 1
A fromException() 0 12 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-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