Passed
Push — master ( 49e3d0...4782d7 )
by Josh
01:10
created

DiffCache::getStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Caxy\HtmlDiff;
4
5
use Doctrine\Common\Cache\Cache;
6
7
/**
8
 * Class DiffCache
9
 * @package Caxy\HtmlDiff
10
 */
11
class DiffCache
12
{
13
    /**
14
     * @var Cache
15
     */
16
    protected $cacheProvider;
17
18
    /**
19
     * DiffCache constructor.
20
     *
21
     * @param Cache $cacheProvider
22
     */
23
    public function __construct(Cache $cacheProvider)
24
    {
25
        $this->cacheProvider = $cacheProvider;
26
    }
27
28
    /**
29
     * @return Cache
30
     */
31
    public function getCacheProvider()
32
    {
33
        return $this->cacheProvider;
34
    }
35
36
    /**
37
     * @param Cache $cacheProvider
38
     *
39
     * @return DiffCache
40
     */
41
    public function setCacheProvider($cacheProvider)
42
    {
43
        $this->cacheProvider = $cacheProvider;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $oldText
50
     * @param string $newText
51
     *
52
     * @return bool
53
     */
54
    public function contains($oldText, $newText)
55
    {
56
        return $this->cacheProvider->contains($this->getHashKey($oldText, $newText));
57
    }
58
59
    /**
60
     * @param string $oldText
61
     * @param string $newText
62
     *
63
     * @return string
64
     */
65
    public function fetch($oldText, $newText)
66
    {
67
        return $this->cacheProvider->fetch($this->getHashKey($oldText, $newText));
68
    }
69
70
    /**
71
     * @param string $oldText
72
     * @param string $newText
73
     * @param string $data
74
     * @param int    $lifeTime
75
     *
76
     * @return bool
77
     */
78
    public function save($oldText, $newText, $data, $lifeTime = 0)
79
    {
80
        return $this->cacheProvider->save($this->getHashKey($oldText, $newText), $data, $lifeTime);
81
    }
82
83
    /**
84
     * @param string $oldText
85
     * @param string $newText
86
     *
87
     * @return bool
88
     */
89
    public function delete($oldText, $newText)
90
    {
91
        return $this->cacheProvider->delete($this->getHashKey($oldText, $newText));
92
    }
93
94
    /**
95
     * @return array|null
96
     */
97
    public function getStats()
98
    {
99
        return $this->cacheProvider->getStats();
100
    }
101
102
    /**
103
     * @param string $oldText
104
     * @param string $newText
105
     *
106
     * @return string
107
     */
108
    protected function getHashKey($oldText, $newText)
109
    {
110
        return sprintf('%s_%s', md5($oldText), md5($newText));
111
    }
112
}
113