ClientFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 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