CachingRequestHandlerDecorator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 22
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chinstrap\Core\Kernel;
6
7
use Laminas\Diactoros\StreamFactory;
8
use Psr\Cache\CacheItemPoolInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
use PublishingKit\HttpProxy\Client;
13
use PublishingKit\HttpProxy\Proxy;
14
15
final class CachingRequestHandlerDecorator implements RequestHandlerInterface
16
{
17
    private RequestHandlerInterface $handler;
18
19
    private CacheItemPoolInterface $cache;
20
21
    public function __construct(RequestHandlerInterface $handler, CacheItemPoolInterface $cache)
22
    {
23
        $this->handler = $handler;
24
        $this->cache = $cache;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30
    public function handle(ServerRequestInterface $request): ResponseInterface
31
    {
32
        $client = new Client(function (ServerRequestInterface $request): ResponseInterface {
33
            return $this->handler->handle($request);
34
        });
35
        $proxy = new Proxy($client, $this->cache, new StreamFactory());
36
        return $proxy->handle($request);
37
    }
38
}
39