Cache::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace Millennium\Cache;
4
5
use Millennium\Cache\Exceptions\DriverMisconfiguredException;
6
use Millennium\Cache\Exceptions\DriverNotFoundException;
7
8
class Cache
9
{
10
    /**
11
     * @var Interfaces\CacheDriverInterface
12
     */
13
    private $driver;
14
15
    public function __construct($driver = null)
16
    {
17
        if (null === $driver) {
18
            throw new DriverMisconfiguredException();
19
        }
20
        if (!$driver instanceof Interfaces\CacheDriverInterface) {
21
            throw new DriverNotFoundException();
22
        }
23
        $this->driver = $driver;
24
    }
25
26
    /**
27
     * @return Interfaces\CacheDriverInterface
28
     */
29
    public function getDriver()
30
    {
31
        return $this->driver;
32
    }
33
34
    /**
35
     * @param string $key
36
     *
37
     * @return array
38
     */
39
    public function fetch($key)
40
    {
41
        return $this->getDriver()->fetch($key);
42
    }
43
44
    /**
45
     * @param string $key
46
     * @param array  $data
47
     *
48
     * @return bool
49
     */
50
    public function store($key, $data)
51
    {
52
        return $this->getDriver()->store($key, $data);
53
    }
54
55
    /**
56
     * @param string $key
57
     *
58
     * @return bool
59
     */
60
    public function remove($key)
61
    {
62
        return $this->getDriver()->remove($key);
63
    }
64
}
65