BoltApp::main()   A
last analyzed

Complexity

Conditions 3
Paths 7

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 2
b 0
f 0
nc 7
nop 0
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 3
rs 9.9332
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\RequestContext;
9
use Lit\Nimo\Middlewares\MiddlewarePipe;
10
use Lit\Voltage\App;
11
use Lit\Voltage\Interfaces\ThrowableResponseInterface;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * Bolt application
16
 */
17
class BoltApp extends App
18
{
19
    public const SETTER_INJECTOR = SetterInjector::class;
20
    /**
21
     * @var ?RequestContext
22
     */
23
    protected $requestContext;
24
25
    /**
26
     * Injector for RequestContext
27
     *
28
     * @param RequestContext|null $requestContext The RequestContext.
29
     * @return $this
30
     */
31 3
    public function injectRequestContext(?RequestContext $requestContext)
32
    {
33 3
        $this->requestContext = $requestContext;
34 3
        return $this;
35
    }
36
37 3
    protected function main(): ResponseInterface
38
    {
39
        try {
40 3
            $middleware = $this->middlewarePipe;
41 3
            if (isset($this->requestContext)) {
42 3
                $pipe = new MiddlewarePipe();
43 3
                $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

43
                $pipe->append(/** @scrutinizer ignore-type */ $this->requestContext);
Loading history...
44 3
                $pipe->append($middleware);
45 3
                $middleware = $pipe;
46
            }
47
48 3
            return $middleware->process($this->request, $this->businessLogicHandler);
49 1
        } catch (ThrowableResponseInterface $e) {
50 1
            return $e->getResponse();
51
        }
52
    }
53
}
54