Multi::remove()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2014, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver;
11
12
/**
13
 * Multi drivers.
14
 *
15
 * The driver is a wrapper for multiple drivers. Takes the driver with quick
16
 * access to the data (stored in memory) and slow (stored on the hard drive),
17
 * and receives data on the possibility of fast drivers and if not luck reads
18
 * data from slow.
19
 */
20
class Multi extends BaseDriver
21
{
22
    /**
23
     * @var DriverInterface
24
     */
25
    protected $fast;
26
27
    /**
28
     * @var DriverInterface
29
     */
30
    protected $slow;
31
32
    /**
33
     * @param DriverInterface $fast
34
     * @param DriverInterface $slow
35
     */
36 7
    public function __construct(DriverInterface $fast, DriverInterface $slow)
37
    {
38 7
        $this->fast = $fast;
39 7
        $this->slow = $slow;
40 7
    }
41
42
    /**
43
     * @param string $key
44
     *
45
     * @return \DateTime|null
46
     */
47 2
    public function get($key)
48
    {
49 2
        if ($time = $this->fast->get($key)) {
50 1
            return $time;
51
        }
52
53 1
        return $this->slow->get($key);
54
    }
55
56
    /**
57
     * @param string $key
58
     * @param \DateTime $time
59
     *
60
     * @return bool
61
     */
62 2
    public function set($key, \DateTime $time)
63
    {
64 2
        if ($this->fast->set($key, $time)) {
65 1
            return $this->slow->set($key, $time);
66
        }
67
68 1
        return false;
69
    }
70
71
    /**
72
     * @param string $key
73
     *
74
     * @return bool
75
     */
76 3
    public function remove($key)
77
    {
78 3
        if ($this->fast->remove($key)) {
79 2
            return $this->slow->remove($key);
80
        }
81
82 1
        return false;
83
    }
84
}
85