CachedLoader   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 13 2
1
<?php
2
3
namespace League\JsonReference\Loader;
4
5
use League\JsonReference\LoaderInterface;
6
use Psr\SimpleCache\CacheInterface;
7
8
final class CachedLoader implements LoaderInterface
9
{
10
    /**
11
     * @var CacheInterface
12
     */
13
    private $cache;
14
15
    /**
16
     * @var LoaderInterface
17
     */
18
    private $loader;
19
20
    /**
21
     * @param CacheInterface  $cache
22
     * @param LoaderInterface $loader
23
     */
24 12
    public function __construct(CacheInterface $cache, LoaderInterface $loader)
25
    {
26 12
        $this->cache  = $cache;
27 12
        $this->loader = $loader;
28 12
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 6
    public function load($path)
34
    {
35 6
        $key   = sha1($path);
36 6
        $value = $this->cache->get($key);
37
38 6
        if ($value !== null) {
39 2
            return $value;
40
        }
41
42 4
        $this->cache->set($key, $value = $this->loader->load($path));
43
44 4
        return $value;
45
    }
46
}
47