Completed
Push — develop ( a32047...d9f18e )
by Jens
03:00
created

Filesystem::getTimestamp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * @author @jayS-de <[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 6
    public function __construct($directory, $debug = false)
22
    {
23 6
        $this->directory = $directory;
24 6
        $this->debug = $debug;
25 6
    }
26
27 2
    public function generateKey($name)
28
    {
29 2
        $hash = hash('sha256', $name);
30
31 2
        return $this->directory.'/'.$hash[0].$hash[1].'/'.$hash.'.php';
32
    }
33
34 3
    public function isFresh($key)
35
    {
36 3
        $cache = new ConfigCache($key, $this->debug);
37 3
        return $cache->isFresh();
38
    }
39
40
    /**
41
     * @param $key
42
     * @return mixed
43
     */
44 2
    public function load($key)
45
    {
46 2
        return @include $key;
47
    }
48
49
    /**
50
     * @param $key
51
     * @param $content
52
     * @param $resources
53
     */
54 4
    public function write($key, $content, $resources)
55
    {
56 4
        $cache = new ConfigCache($key, $this->debug);
57 4
        $cache->write($content, $resources);
58
59 4
        return;
60
    }
61
}
62