FileCacheDriver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 47
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 8 3
A save() 0 8 2
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