HttpApplication::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace N1215\Tsukuyomi;
5
6
use Psr\Http\Server\RequestHandlerInterface;
7
use N1215\Tsukuyomi\Event\AppTerminating;
8
use N1215\Tsukuyomi\Event\EventManagerInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Laminas\HttpHandlerRunner\Emitter\EmitterInterface;
11
12
class HttpApplication implements HttpApplicationInterface
13
{
14
    /** @var BootLoaderInterface  */
15
    private $bootLoader;
16
17
    /** @var EventManagerInterface  */
18
    private $eventManager;
19
20
    /** @var RequestHandlerInterface  */
21
    private $requestHandler;
22
23
    /** @var EmitterInterface  */
24
    private $responseEmitter;
25
26 1
    public function __construct(
27
        BootLoaderInterface $bootLoader,
28
        RequestHandlerInterface $requestHandler,
29
        EmitterInterface $responseEmitter,
30
        EventManagerInterface $eventManager
31
    ) {
32 1
        $this->bootLoader = $bootLoader;
33 1
        $this->requestHandler = $requestHandler;
34 1
        $this->responseEmitter = $responseEmitter;
35 1
        $this->eventManager = $eventManager;
36 1
    }
37
38 1
    public function run(ServerRequestInterface $request): void
39
    {
40 1
        $this->bootLoader->boot();
41 1
        $response = $this->requestHandler->handle($request);
42 1
        $this->responseEmitter->emit($response);
43 1
        $this->eventManager->trigger(new AppTerminating($request, $response));
44 1
        return;
45
    }
46
}
47