FileCacheDriver::load()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Arthem\GraphQLMapper\Mapping\Cache;
4
5
use Arthem\GraphQLMapper\Mapping\SchemaContainer;
6
7
class FileCacheDriver implements CacheDriverInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $cacheFile;
13
14
    /**
15
     * @var bool
16
     */
17
    private $cacheEnabled;
18
19
    /**
20
     * @param string $cacheFile
21
     * @param bool   $cacheEnabled
22
     */
23
    public function __construct($cacheFile, $cacheEnabled = true)
24
    {
25
        $this->cacheFile    = $cacheFile;
26
        $this->cacheEnabled = $cacheEnabled;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function load()
33
    {
34
        if (!$this->cacheEnabled || !is_file($this->cacheFile)) {
35
            return false;
36
        }
37
38
        return unserialize(file_get_contents($this->cacheFile));
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function save(SchemaContainer $container)
45
    {
46
        if (!$this->cacheEnabled) {
47
            return;
48
        }
49
50
        file_put_contents($this->cacheFile, serialize($container));
51
    }
52
53
}
54