StubResolveException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 5
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 1
rs 10
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 1
    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 1
        parent::__construct($message, $code, $previous);
40 1
        $this->stub = $stub;
41 1
        $this->factory = $factory;
42 1
    }
43
44
    /**
45
     * @return mixed
46
     */
47 1
    public function getStub()
48
    {
49 1
        return $this->stub;
50
    }
51
52
    /**
53
     * @return ResponseInterface
54
     */
55 1
    public function getResponse(): ResponseInterface
56
    {
57 1
        $response = $this->factory->createResponse(404);
58 1
        $response->getBody()->write('not found');
59
60 1
        return $response;
61
    }
62
}
63