Test Failed
Push — master ( ebe86f...4efdc4 )
by mcfog
02:46
created

StubResolveException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 46
ccs 0
cts 20
cp 0
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getStub() 0 3 1
A getResponse() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Bolt\Router;
6
7
use Lit\Voltage\Interfaces\ThrowableResponseInterface;
8
use Psr\Http\Message\ResponseFactoryInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use Throwable;
11
12
/**
13
 * Stub resolving exception
14
 */
15
class StubResolveException extends \RuntimeException implements ThrowableResponseInterface
16
{
17
    protected $stub;
18
    /**
19
     * @var ResponseFactoryInterface
20
     */
21
    protected $factory;
22
23
    /**
24
     * StubResolveException constructor.
25
     *
26
     * @param mixed                    $stub     The problematic stub.
27
     * @param ResponseFactoryInterface $factory  Response factory used to create not found response.
28
     * @param Throwable|null           $previous Previous exception.
29
     * @param string                   $message  Exception message.
30
     * @param integer                  $code     Exception code.
31
     */
32
    public function __construct(
33
        $stub,
34
        ResponseFactoryInterface $factory,
35
        Throwable $previous = null,
36
        string $message = 'router stub parse failed',
37
        int $code = 0
38
    ) {
39
        parent::__construct($message, $code, $previous);
40
        $this->stub = $stub;
41
        $this->factory = $factory;
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47
    public function getStub()
48
    {
49
        return $this->stub;
50
    }
51
52
    /**
53
     * @return ResponseInterface
54
     */
55
    public function getResponse(): ResponseInterface
56
    {
57
        $response = $this->factory->createResponse(404);
58
        $response->getBody()->write('not found');
59
60
        return $response;
61
    }
62
}
63