CachedDiscoverer::discover()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 2
nc 2
nop 1
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