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

FastlyCachePurgeModule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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