Passed
Push — main ( dae7cc...12f243 )
by Breno
01:47
created

AttributesMapperCache::mapHandlers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace OniBus\Handler\Attributes;
5
6
use OniBus\Handler\Attributes\AttributesMapperInterface;
7
use Psr\SimpleCache\CacheInterface;
8
9
/**
10
 * Decorator
11
 */
12
class AttributesMapperCache implements AttributesMapperInterface
13
{
14
    /**
15
     * @var AttributesMapperInterface
16
     */
17
    protected $mapper;
18
19
    /**
20
     * @var string
21
     */
22
    private $cacheKey;
23
24
    /**
25
     * @var CacheInterface
26
     */
27
    private $cache;
28
29
    public function __construct(AttributesMapperInterface $mapper, CacheInterface $cache, string $cacheKey)
30
    {
31
        $this->mapper = $mapper;
32
        $this->cache = $cache;
33
        $this->cacheKey = $cacheKey;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function mapHandlers(): array
40
    {
41
        if ($this->cache->has($this->cacheKey)) {
42
            return $this->cache->get($this->cacheKey);
43
        }
44
45
        $mapped = $this->mapper->mapHandlers();
46
        $this->cache->set($this->cacheKey, $mapped);
47
        return $mapped;
48
    }
49
}
50