Completed
Push — master ( fd9d43...1b1cd4 )
by Matthew
02:57
created

Proxy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PublishingKit\HttpProxy;
6
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Cache\CacheItemPoolInterface;
10
use Http\Client\HttpClient;
11
use Http\Client\Common\PluginClient;
12
use Http\Client\Common\Plugin\CachePlugin;
13
use Http\Message\StreamFactory;
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 StreamFactory
29
     */
30
    private $streamFactory;
31
32 3
    public function __construct(HttpClient $client, CacheItemPoolInterface $cache, StreamFactory $streamFactory)
33
    {
34 3
        $this->client = $client;
35 3
        $this->cache = $cache;
36 3
        $this->streamFactory = $streamFactory;
37 3
    }
38
39 3
    public function handle(RequestInterface $request): ResponseInterface
40
    {
41 3
        $cachePlugin = new CachePlugin($this->cache, $this->streamFactory, []);
42
43 3
        $pluginClient = new PluginClient(
44 3
            $this->client,
45 3
            [$cachePlugin]
46
        );
47 3
        return $pluginClient->sendRequest($request);
48
    }
49
}
50