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

CacheConfiguration   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getStrategy() 0 4 1
B create() 0 10 5
A disabled() 0 7 1
A getTtl() 0 4 1
A isEnabled() 0 4 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
    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