SimpleCallbackAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 11 2
1
<?php
2
namespace Genkgo\Cache\Adapter;
3
4
use Genkgo\Cache\CacheAdapterInterface;
5
use Genkgo\Cache\CallbackCacheInterface;
6
7
/**
8
 * Class SimpleCallbackAdapter
9
 * @package Genkgo\Cache
10
 */
11
class SimpleCallbackAdapter implements CallbackCacheInterface
12
{
13
    /**
14
     * @var CacheAdapterInterface
15
     */
16
    private $cache;
17
18
    /**
19
     * @param CacheAdapterInterface $cache
20
     */
21 2
    public function __construct(CacheAdapterInterface $cache)
22
    {
23 2
        $this->cache = $cache;
24 2
    }
25
26
    /**
27
     * @param $key
28
     * @param callable $cb
29
     * @return mixed|null
30
     */
31 2
    public function get($key, callable $cb)
32
    {
33 2
        $item = $this->cache->get($key);
34 2
        if ($item === null) {
35 1
            $item = $cb();
36 1
            $this->cache->set($key, $item);
37 1
            return $item;
38
        } else {
39 1
            return $item;
40
        }
41
    }
42
}
43