CachedDiscoverer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A discover() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\OpenIDConnect\Discovery;
6
7
use Psr\SimpleCache\CacheInterface;
8
9
final class CachedDiscoverer implements Discoverer
10
{
11
    public const DEFAULT_TTL = 3600;
12
13
    public function __construct(
14
        private Discoverer $inner,
15
        private CacheInterface $cache,
16
        private int $ttl = self::DEFAULT_TTL
17
    ) {
18
    }
19
20
    public function discover(string $uri): ProviderMetadata
21
    {
22
        $key = 'oidc_discoverer_' . base64_encode($uri);
23
24
        if ($this->cache->has($key)) {
25
            return $this->cache->get($key);
26
        }
27
28
        $metadata = $this->inner->discover($uri);
29
        $this->cache->set($key, $metadata, $this->ttl);
30
31
        return $metadata;
32
    }
33
}
34