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

FormulaEngineException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 41
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromException() 0 17 4
A create() 0 10 2
A getFormula() 0 4 1
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