Passed
Pull Request — master (#34)
by Anatoly
02:14
created

Exception   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromContext() 0 3 1
A getContext() 0 3 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\Exception;
13
14
/**
15
 * Import classes
16
 */
17
use RuntimeException;
18
use Throwable;
19
20
/**
21
 * Exception
22
 */
23
class Exception extends RuntimeException implements ExceptionInterface
24
{
25
26
    /**
27
     * Context of the exception
28
     *
29
     * @var array
30
     */
31
    private $context = [];
32
33
    /**
34
     * Constructor of the exception
35
     *
36
     * @param string    $message
37
     * @param array     $context
38
     * @param int       $code
39
     * @param Throwable $previous
40
     */
41 295
    public function __construct(string $message = '', array $context = [], int $code = 0, Throwable $previous = null)
42
    {
43 295
        $this->context = $context;
44
45 295
        parent::__construct($message, $code, $previous);
46 295
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 19
    final public function getContext() : array
52
    {
53 19
        return $this->context;
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59 11
    final public function fromContext($key, $default = null)
60
    {
61 11
        return $this->context[$key] ?? $default;
62
    }
63
}
64