Passed
Pull Request — 1.x (#125)
by
unknown
02:28
created

FastlyPurgeModule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository\Cdn;
6
7
use BEAR\QueryRepository\PurgerInterface;
8
use Fastly\Api\PurgeApi;
9
use Fastly\Configuration;
10
use GuzzleHttp\Client;
11
use GuzzleHttp\ClientInterface;
12
use Ray\Di\AbstractModule;
13
use Ray\Di\Scope;
14
15
final class FastlyPurgeModule extends AbstractModule
16
{
17
    /** @SuppressWarnings("PHPMD.BooleanArgumentFlag") */
18
    public function __construct(
19
        private string $fastlyApiKey,
20
        private string $fastlyServiceId,
21
        private bool $enableSoftPurge = true,
22
        AbstractModule|null $module = null,
23
    ) {
24
        parent::__construct($module);
25
    }
26
27
    /** {@inheritdoc} */
28
    protected function configure(): void
29
    {
30
        $this->bind(Configuration::class)->annotatedWith(Configuration::class)->toInstance(
31
            Configuration::getDefaultConfiguration()->setApiToken($this->fastlyApiKey),
32
        );
33
        $this->bind(PurgeApi::class)->toConstructor(PurgeApi::class, [
34
            'config' => Configuration::class,
35
        ])->in(Scope::SINGLETON);
36
        $this->bind()->annotatedWith('fastlyServiceId')->toInstance($this->fastlyServiceId);
37
        $this->bind()->annotatedWith('fastlyEnableSoftPurge')->toInstance($this->enableSoftPurge);
38
        $this->bind(ClientInterface::class)->annotatedWith('fastlyApi')
39
            ->toConstructor(Client::class, ['config' => 'fastly_http_client_options']);
40
        $this->bind(PurgerInterface::class)->to(FastlyCachePurger::class);
41
    }
42
}
43