Completed
Push — develop ( 7b6eba...aad3df )
by Jens
03:19
created

Filesystem::isFresh()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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