Completed
Push — master ( baff27...3a9c47 )
by Daniel
02:56
created

CacheProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

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 12
cts 12
cp 1
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 4
    public function __construct(Config $config)
42
    {
43 4
        $this->config = $config;
44 4
    }
45
46
    /**
47
     * Get cache.
48
     *
49
     * @return Cache
50
     */
51 4
    public function getCache()
52
    {
53 4
        if (null === $this->cache) {
54 4
            $directory = $this->config->getCacheDirectory();
55 4
            if (null === $directory) {
56 2
                $this->cache = new ArrayCache();
57
58 2
                return $this->cache;
59
            }
60
61 2
            $this->cache = new FilesystemCache($directory);
62 1
        }
63
64 2
        return $this->cache;
65
    }
66
}
67