Completed
Push — master ( 5db45c...f208af )
by Arthur
02:39
created

FileCacheDriver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 4
c 1
b 1
f 1
lcom 1
cbo 0
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 8 2
A save() 0 4 1
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
     * @param string $cacheFile
16
     */
17
    public function __construct($cacheFile)
18
    {
19
        $this->cacheFile = $cacheFile;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function load()
26
    {
27
        if (!is_file($this->cacheFile)) {
28
            return false;
29
        }
30
31
        return unserialize(file_get_contents($this->cacheFile));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function save(SchemaContainer $container)
38
    {
39
        file_put_contents($this->cacheFile, serialize($container));
40
    }
41
42
}
43