Completed
Branch master (1b1cd4)
by Matthew
01:20
created

Proxy::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
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