Completed
Push — master ( 1e2cfa...28995d )
by Eric
04:38
created

CacheNamingStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Naming;
13
14
use Psr\Cache\CacheItemPoolInterface;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class CacheNamingStrategy extends AbstractNamingStrategy
20
{
21
    /**
22
     * @var NamingStrategyInterface
23
     */
24
    private $strategy;
25
26
    /**
27
     * @var CacheItemPoolInterface
28
     */
29
    private $cache;
30
31
    /**
32
     * @param NamingStrategyInterface $strategy
33
     * @param CacheItemPoolInterface  $cache
34
     */
35 8
    public function __construct(NamingStrategyInterface $strategy, CacheItemPoolInterface $cache)
36
    {
37 8
        $this->strategy = $strategy;
38 8
        $this->cache = $cache;
39 8
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 8
    protected function doConvert($name)
45
    {
46 8
        $item = $this->cache->getItem($name);
47
48 8
        if ($item->isHit()) {
49 4
            return $item->get();
50
        }
51
52 4
        $result = $this->strategy->convert($name);
53 4
        $this->cache->save($item->set($result));
54
55 4
        return $result;
56
    }
57
}
58