Completed
Push — master ( c91a90...e32b70 )
by Chris
02:54
created

Exception::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\Jom\Exceptions;
4
5
abstract class Exception extends \Exception
6
{
7 73
    /**
8
     * @param string $format
9 73
     * @param mixed ...$args
10
     * @return static
11
     */
12
    public static function withMessage(string $format, ...$args): self
13 73
    {
14
        return new static(\vsprintf($format, $args));
15
    }
16
17
    public function __construct($message, $code = 0, \Throwable $previous = null)
18 73
    {
19
        if ($message instanceof \Throwable) {
20
            parent::__construct($message->getMessage(), $message->getCode(), $message);
21
            return;
22
        }
23
24
        if ($code instanceof \Throwable) {
25
            parent::__construct((string)$message, $code->getCode(), $code);
26
            return;
27
        }
28
29
        parent::__construct((string)$message, (int)$code, $previous);
30
    }
31
}
32