CachedExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractClassMethods() 0 9 2
A __construct() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace OniBus\Handler\ClassMethod\Extractor;
5
6
use OniBus\Handler\ClassMethod\ClassMethodExtractor;
7
use Psr\SimpleCache\CacheInterface;
8
9
/**
10
 * Decorator
11
 */
12
class CachedExtractor implements ClassMethodExtractor
13
{
14
    /**
15
     * @var ClassMethodExtractor
16
     */
17
    protected $extractor;
18
19
    /**
20
     * @var string
21
     */
22
    private $cacheKey;
23
24
    /**
25
     * @var CacheInterface
26
     */
27
    private $cache;
28
29
    public function __construct(ClassMethodExtractor $extractor, CacheInterface $cache, string $cacheKey)
30
    {
31
        $this->extractor = $extractor;
32
        $this->cache = $cache;
33
        $this->cacheKey = $cacheKey;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function extractClassMethods(): array
40
    {
41
        if ($this->cache->has($this->cacheKey)) {
42
            return $this->cache->get($this->cacheKey);
43
        }
44
45
        $classMethods = $this->extractor->extractClassMethods();
46
        $this->cache->set($this->cacheKey, $classMethods);
47
        return $classMethods;
48
    }
49
}
50