CachedProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A provide() 0 13 2
1
<?php
2
3
namespace ICanBoogie\CLDR\Provider;
4
5
use ICanBoogie\CLDR\Cache;
6
use ICanBoogie\CLDR\Provider;
7
8
/**
9
 * Decorate a provider with caching features.
10
 */
11
final class CachedProvider implements Provider
12
{
13
    public function __construct(
14
        private readonly Provider $provider,
15
        private readonly Cache $cache
16
    ) {
17
    }
18
19
    /**
20
     * @inheritDoc
21
     */
22
    public function provide(string $path): array
23
    {
24
        $data = $this->cache->get($path);
25
26
        if ($data !== null) {
27
            return $data;
28
        }
29
30
        $data = $this->provider->provide($path);
31
32
        $this->cache->set($path, $data);
33
34
        return $data;
35
    }
36
}
37