BoltApp   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 15
c 4
b 0
f 0
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A injectRequestContext() 0 4 1
A main() 0 14 3
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