UnhandledRejectionException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
wmc 4
lcom 0
cbo 0
ccs 9
cts 11
cp 0.8182
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 8 2
A __construct() 0 8 1
A getReason() 0 4 1
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