UnhandledRejectionException::getReason()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Thruster\Component\Promise\Exception;
4
5
/**
6
 * Class UnhandledRejectionException
7
 *
8
 * @package Thruster\Component\Promise\Exception
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
class UnhandledRejectionException extends \RuntimeException
12
{
13
    private $reason;
14
15 45
    public static function resolve($reason)
16
    {
17 45
        if ($reason instanceof \Exception) {
18 21
            return $reason;
19
        }
20
21 24
        return new static($reason);
22
    }
23
24 24
    public function __construct($reason)
25
    {
26 24
        $this->reason = $reason;
27
28 24
        $message = sprintf('Unhandled Rejection: %s', json_encode($reason));
29
30 24
        parent::__construct($message, 0);
31 24
    }
32
33
    public function getReason()
34
    {
35
        return $this->reason;
36
    }
37
}
38