Repository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A forget() 0 3 1
A keyFor() 0 3 1
A parse() 0 4 1
A remember() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author enea dhack <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Enea\Authorization\Drivers\Cache\Repositories;
13
14
use Closure;
15
use Enea\Authorization\Contracts\Grantable;
16
use Enea\Authorization\Contracts\Owner;
17
use Enea\Authorization\Drivers\Cache\CacheConfig;
18
use Enea\Authorization\Drivers\Cache\KeyBuilder;
19
use Enea\Authorization\Drivers\Cache\Struct;
20
use Illuminate\Cache\Repository as Cache;
21
use Illuminate\Support\Collection;
22
23
abstract class Repository
24
{
25
    private $cache;
26
27
    private $key;
28
29 60
    public function __construct(Cache $cache, KeyBuilder $key)
30
    {
31 60
        $this->cache = $cache;
32 60
        $this->key = $key;
33 60
    }
34
35
    abstract public static function getSuffix(): string;
36
37 52
    public function forget(Owner $owner): void
38
    {
39 52
        $this->cache->forget($this->keyFor($owner));
40 52
    }
41
42 43
    protected function remember(Owner $owner, Closure $closure): Collection
43
    {
44 43
        $minutes = CacheConfig::getExpirationTime();
45 43
        return $this->cache->remember($this->keyFor($owner), $minutes, $closure);
46
    }
47
48 58
    protected function keyFor(Owner $owner): string
49
    {
50 58
        return "{$this->key->make($owner)}.{$this->getSuffix()}";
51
    }
52
53 43
    protected function parse(): Closure
54
    {
55 43
        return function (Grantable $grantable): Struct {
56 27
            return Struct::make($grantable->getSecretName());
57 43
        };
58
    }
59
}
60