Completed
Push — master ( 9ce2ea...baff27 )
by Daniel
12:24
created

CacheProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 47
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCache() 0 15 3
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Provider;
9
10
use Doctrine\Common\Cache\ArrayCache;
11
use Doctrine\Common\Cache\Cache;
12
use Doctrine\Common\Cache\FilesystemCache;
13
use GravityMedia\Commander\Config;
14
15
/**
16
 * Cache provider class.
17
 *
18
 * @package GravityMedia\Commander\Provider
19
 */
20
class CacheProvider
21
{
22
    /**
23
     * The config.
24
     *
25
     * @var Config
26
     */
27
    protected $config;
28
29
    /**
30
     * The cache.
31
     *
32
     * @var Cache
33
     */
34
    protected $cache;
35
36
    /**
37
     * Create cache provider object.
38
     *
39
     * @param Config $config
40
     */
41
    public function __construct(Config $config)
42
    {
43
        $this->config = $config;
44
    }
45
46
    /**
47
     * Get cache.
48
     *
49
     * @return Cache
50
     */
51
    public function getCache()
52
    {
53
        if (null === $this->cache) {
54
            $directory = $this->config->getCacheDirectory();
55
            if (null === $directory) {
56
                $this->cache = new ArrayCache();
57
58
                return $this->cache;
59
            }
60
61
            $this->cache = new FilesystemCache($directory);
62
        }
63
64
        return $this->cache;
65
    }
66
}
67