Completed
Pull Request — master (#14)
by Pavel
29:07 queued 23:49
created

CacheConfiguration::disabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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