Server::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aidphp\Framework;
6
7
use Interop\Http\PhpServerRequestFactoryInterface;
8
use Psr\Http\Server\RequestHandlerInterface;
9
use Aidphp\Error\ErrorHandlerInterface;
10
use Interop\Http\EmitterInterface;
11
use Throwable;
12
13
class Server
14
{
15
    protected $requestFactory;
16
    protected $handler;
17
    protected $errorHandler;
18
    protected $emitter;
19
20 2
    public function __construct(PhpServerRequestFactoryInterface $requestFactory, RequestHandlerInterface $handler, ErrorHandlerInterface $errorHandler, EmitterInterface $emitter)
21
    {
22 2
        $this->requestFactory = $requestFactory;
23 2
        $this->handler = $handler;
24 2
        $this->errorHandler = $errorHandler;
25 2
        $this->emitter = $emitter;
26 2
    }
27
28 2
    public function run(): void
29
    {
30
        try
31
        {
32 2
            $res = $this->handler->handle($this->requestFactory->createServerRequestFromGlobals());
33
        }
34 1
        catch (Throwable $e)
35
        {
36 1
            $res = $this->errorHandler->handleError($e);
37
        }
38
39 2
        $this->emitter->emit($res);
40
    }
41
}