Passed
Branch master (36c4fb)
by mcfog
02:35
created

BoltApp::injectRequestContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Bolt;
6
7
use Lit\Air\Injection\SetterInjector;
8
use Lit\Bolt\Middlewares\EventsHub;
9
use Lit\Bolt\Middlewares\RequestContext;
10
use Lit\Nimo\Middlewares\MiddlewarePipe;
11
use Lit\Voltage\App;
12
use Lit\Voltage\Interfaces\ThrowableResponseInterface;
13
use Psr\Http\Message\ResponseInterface;
14
15
class BoltApp extends App
16
{
17
    const SETTER_INJECTOR = SetterInjector::class;
18
    /**
19
     * @var ?EventsHub
20
     */
21
    protected $eventsHub;
22
    /**
23
     * @var ?RequestContext
24
     */
25
    protected $requestContext;
26
27 2
    public function injectEventsHub(?EventsHub $eventsHub)
28
    {
29 2
        $this->eventsHub = $eventsHub;
30 2
        return $this;
31
    }
32
33 2
    public function injectRequestContext(?RequestContext $requestContext)
34
    {
35 2
        $this->requestContext = $requestContext;
36 2
        return $this;
37
    }
38
39
    /**
40
     * @return EventsHub
41
     */
42
    public function getEventsHub(): EventsHub
43
    {
44
        assert($this->eventsHub !== null);
45
        return $this->eventsHub;
46
    }
47
48 2
    protected function main(): ResponseInterface
49
    {
50
        try {
51 2
            $pipe = new MiddlewarePipe();
52 2
            if (isset($this->requestContext)) {
53 2
                $pipe->append($this->requestContext);
0 ignored issues
show
Bug introduced by
It seems like $this->requestContext can also be of type null; however, parameter $middleware of Lit\Nimo\Middlewares\MiddlewarePipe::append() does only seem to accept Psr\Http\Server\MiddlewareInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
                $pipe->append(/** @scrutinizer ignore-type */ $this->requestContext);
Loading history...
54
            }
55 2
            if (isset($this->eventsHub)) {
56 2
                $pipe->append($this->eventsHub);
57
            }
58 2
            $pipe->append($this->middlewarePipe);
59
60 2
            return $pipe->process($this->request, $this->businessLogicHandler);
61
        } catch (ThrowableResponseInterface $e) {
62
            return $e->getResponse();
63
        }
64
    }
65
}
66