Completed
Pull Request — master (#14)
by Pavel
05:32 queued 02:29
created

CacheConfiguration::getStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Cache;
4
5
class CacheConfiguration
6
{
7
    /** @var int|null */
8
    private $ttl;
9
    /** @var bool */
10
    private $enabled = false;
11
    /** @var KeyStrategyInterface */
12
    private $strategy;
13
14 17
    private function __construct()
15
    {
16 17
    }
17
18
    /**
19
     * @return KeyStrategyInterface
20
     */
21 1
    public function getStrategy()
22
    {
23 1
        return $this->strategy;
24
    }
25
26
    /**
27
     * @param array $data
28
     *
29
     * @return static
30
     */
31 1
    public static function create(array $data)
32
    {
33 1
        $configuration           = new static();
34 1
        $configuration->ttl      =
35 1
            array_key_exists('enabled', $data) && null !== $data['enabled'] ? (int)$data['ttl'] : null;
36 1
        $configuration->enabled  = array_key_exists('enabled', $data) ? (bool)$data['enabled'] : false;
37 1
        $configuration->strategy = array_key_exists('strategy', $data) ? $data['strategy'] : new ScalarKeyStrategy();
38
39 1
        return $configuration;
40
    }
41
42
    /**
43
     * Constructor for disabled cache entities configuration
44
     *
45
     * @return static
46
     */
47 16
    public static function disabled()
48
    {
49 16
        $configuration          = new static();
50 16
        $configuration->enabled = false;
51
52 16
        return $configuration;
53
    }
54
55
    /**
56
     * @return int|null
57
     */
58 1
    public function getTtl()
59
    {
60 1
        return $this->ttl;
61
    }
62
63
    /**
64
     * @return boolean
65
     */
66 17
    public function isEnabled()
67
    {
68 17
        return $this->enabled;
69
    }
70
}
71