Completed
Push — master ( 9a342a...a162ae )
by Andrii
13:06
created

ResolveEndpointMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 8 1
1
<?php
2
3
namespace hiapi\Core\Http\Psr15\Middleware;
4
5
use hiapi\Core\Endpoint\EndpointRepository;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
11
/**
12
 * Class ResolveEndpointMiddleware
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16
class ResolveEndpointMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @var EndpointRepository
20
     */
21
    private $endpointRepository;
22
23
    public function __construct(EndpointRepository $endpointRepository)
24
    {
25
        $this->endpointRepository = $endpointRepository;
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
32
    {
33
        $endpoint = $this->endpointRepository->getByName(trim($request->getUri()->getPath(), '/'));
34
35
        return $handler->handle(
36
            $request->withAttribute(self::class, $endpoint)
37
        );
38
    }
39
}
40