Server   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A run() 0 13 2
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
}