CachedProvider::provide()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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