Filesystem::isFresh()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
7
namespace JaySDe\HandlebarsBundle\Cache;
8
9
10
use Symfony\Component\Config\ConfigCache;
11
12
class Filesystem
13
{
14
    private $directory;
15
    private $debug;
16
17
    /**
18
     * @param $directory string The root cache directory
19
     * @param bool $debug
20
     */
21 8
    public function __construct($directory, $debug = false)
22
    {
23 8
        $this->directory = $directory;
24 8
        $this->debug = $debug;
25 8
    }
26
27 4
    public function generateKey($name)
28
    {
29 4
        $hash = hash('sha256', $name);
30
31 4
        return $this->directory.'/'.$hash[0].$hash[1].'/'.$hash.'.php';
32
    }
33
34 2
    public function isFresh($key)
35
    {
36 2
        $cache = new ConfigCache($key, $this->debug);
37 2
        return $cache->isFresh();
38
    }
39
40
    /**
41
     * @param $key
42
     * @return mixed
43
     */
44 4
    public function load($key)
45
    {
46 4
        return @include $key;
47
    }
48
49
    /**
50
     * @param $key
51
     * @param $content
52
     * @param $resources
53
     */
54 6
    public function write($key, $content, $resources)
55
    {
56 6
        $cache = new ConfigCache($key, $this->debug);
57 6
        $cache->write($content, $resources);
58
59 6
        return;
60
    }
61
}
62