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

FileCacheDriver::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 8
rs 9.4286
cc 2
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
     * @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