SetRepository::deleteFeatureSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\Doorkeeper\Features;
6
7
use Psr\Cache;
8
9
final class SetRepository
10
{
11
    private Cache\CacheItemPoolInterface $cache;
12
13
    public function __construct(Cache\CacheItemPoolInterface $cache)
14
    {
15
        $this->cache = $cache;
16
    }
17
18
    public function saveFeatureSet(Set $set): void
19
    {
20
        $cacheItem = $this->cache->getItem(self::generateFeatureSetCacheKey());
21
        $cacheItem->set($set);
22
23
        $this->cache->save($cacheItem);
24
    }
25
26
    public function getFeatureSet(SetProviderInterface $fallback = null): Set
27
    {
28
        $result = $this->cache->getItem(self::generateFeatureSetCacheKey())->get();
29
30
        if (!$result && $fallback) {
31
            $result = $fallback->getFeatureSet();
32
            $this->saveFeatureSet($fallback->getFeatureSet());
33
        }
34
35
        return ($result) ?? new Set();
36
    }
37
38
    public function deleteFeatureSet(): void
39
    {
40
        $this->cache->deleteItem(self::generateFeatureSetCacheKey());
41
    }
42
43
    public static function generateFeatureSetCacheKey(): string
44
    {
45
        return md5(self::class);
46
    }
47
}
48