Proxy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 12
c 3
b 1
f 0
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PublishingKit\HttpProxy;
6
7
use Http\Client\Common\PluginClient;
8
use Http\Client\Common\Plugin\CachePlugin;
9
use Http\Client\HttpClient;
10
use Psr\Cache\CacheItemPoolInterface;
11
use Psr\Http\Message\RequestInterface;
12
use Psr\Http\Message\ResponseInterface;
13
use Psr\Http\Message\StreamFactoryInterface;
14
15
final class Proxy
16
{
17
    /**
18
     * @var HttpClient
19
     */
20
    private $client;
21
22
    /**
23
     * @var CacheItemPoolInterface
24
     */
25
    private $cache;
26
27
    /**
28
     * @var StreamFactoryInterface
29
     */
30
    private $streamFactory;
31
32 3
    public function __construct(
33
        HttpClient $client,
34 3
        CacheItemPoolInterface $cache,
35 3
        StreamFactoryInterface $streamFactory
36 3
    ) {
37 3
        $this->client = $client;
38
        $this->cache = $cache;
39 3
        $this->streamFactory = $streamFactory;
40
    }
41 3
42
    public function handle(RequestInterface $request): ResponseInterface
43 3
    {
44 3
        $cachePlugin = new CachePlugin($this->cache, $this->streamFactory, []);
45 3
46
        $pluginClient = new PluginClient(
47 3
            $this->client,
48
            [$cachePlugin]
49
        );
50
        return $pluginClient->sendRequest($request);
51
    }
52
}
53