ClientFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A make() 0 11 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\Http;
6
7
use GrahamCampbell\GuzzleFactory\GuzzleFactory;
8
use GuzzleHttp\ClientInterface;
9
use GuzzleHttp\HandlerStack;
10
use Kevinrob\GuzzleCache\CacheMiddleware;
11
use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage;
12
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;
13
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
14
15
class ClientFactory
16
{
17
    /**
18
     * @var GuzzleFactory
19
     */
20
    protected $guzzleFactory;
21
22
    /**
23
     * ClientFactory constructor.
24
     *
25
     * @param GuzzleFactory $guzzleFactory
26
     */
27
    public function __construct(GuzzleFactory $guzzleFactory)
28
    {
29
        $this->guzzleFactory = $guzzleFactory;
30
    }
31
32
    /**
33
     * @SuppressWarnings(PHPMD.StaticAccess)
34
     *
35
     * @return ClientInterface
36
     */
37
    public function make(): ClientInterface
38
    {
39
        $stack                = HandlerStack::create();
40
        $cacheStorage         = new Psr6CacheStorage(
41
            new FilesystemAdapter('ExchangeRatesApp', 0, '/tmp/')
42
        );
43
        $privateCacheStrategy = new PrivateCacheStrategy($cacheStorage);
44
45
        $stack->push(new CacheMiddleware($privateCacheStrategy), 'cache');
46
47
        return $this->guzzleFactory::make(['handler' => $stack]);
48
    }
49
}
50