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

FastlyPurgeModule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
    /**
18
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
19
     */
20
    public function __construct(
21
        private string $fastlyApiKey,
22
        private string $fastlyServiceId,
23
        private bool $enableSoftPurge = true,
24
        ?AbstractModule $module = null
25
    ) {
26
        parent::__construct($module);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function configure(): void
33
    {
34
        $this->bind(Configuration::class)->annotatedWith(Configuration::class)->toInstance(
35
            Configuration::getDefaultConfiguration()->setApiToken($this->fastlyApiKey)
36
        );
37
        $this->bind(PurgeApi::class)->toConstructor(PurgeApi::class, [
38
            'config' => Configuration::class,
39
        ])->in(Scope::SINGLETON);
40
        $this->bind()->annotatedWith('fastlyServiceId')->toInstance($this->fastlyServiceId);
41
        $this->bind()->annotatedWith('fastlyEnableSoftPurge')->toInstance($this->enableSoftPurge);
42
        $this->bind(ClientInterface::class)->annotatedWith('fastlyApi')
43
            ->toConstructor(Client::class, ['config' => 'fastly_http_client_options']);
44
        $this->bind(PurgerInterface::class)->to(FastlyCachePurger::class);
45
    }
46
}
47