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

FastlyCachePurger   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 1
A __construct() 0 5 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\ApiException;
10
use Ray\Di\Di\Named;
11
12
use function explode;
13
14
final class FastlyCachePurger implements PurgerInterface
15
{
16
    /**
17
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
18
     * @Named("fastlyServiceId=fastlyServiceId,enableSoftPurge=fastlyEnableSofrPurge")
19
     */
20
    public function __construct(
21
        private PurgeApi $purgeApi,
22
        #[Named('fastlyServiceId')] private string $fastlyServiceId,
23
        #[Named('fastlyEnableSoftPurge')] private bool $enableSoftPurge
24
    ) {
25
    }
26
27
    /**
28
     * @throws ApiException
29
     *
30
     * @see https://developer.fastly.com/reference/api/purging/
31
     */
32
    public function __invoke(string $tag): void
33
    {
34
        $this->purgeApi->bulkPurgeTag([
35
            'fastly_soft_purge' => (int) $this->enableSoftPurge,
36
            'service_id' => $this->fastlyServiceId,
37
            'purge_response' => ['surrogate_keys' => explode(' ', $tag)],
38
        ]);
39
    }
40
}
41