FileCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 4
c 2
b 1
f 1
lcom 0
cbo 2
dl 0
loc 43
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A isFresh() 0 4 1
A __destruct() 0 12 1
1
<?php
2
3
namespace Innmind\RestBundle\Client\Server\Cache;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
7
class FileCache extends InMemoryCache
8
{
9
    protected $filePath;
10
    protected $filesystem;
11
    protected $isFresh = true;
12
13 10
    public function __construct($filePath)
14
    {
15 10
        $this->filePath = (string) $filePath;
16 10
        $this->filesystem = new Filesystem;
17
18 10
        if ($this->filesystem->exists($this->filePath)) {
19 4
            $this->data = require $this->filePath;
20 4
            $this->isFresh = false;
21 4
        }
22 10
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 2
    public function isFresh()
28
    {
29 2
        return $this->isFresh;
30
    }
31
32
    /**
33
     * Dump the couples to the file
34
     *
35
     * @return void
36
     */
37 6
    public function __destruct()
38
    {
39 6
        $dump = var_export($this->data, true);
40
        $code = <<<PHP
41
<?php
42
43
return $dump;
44
45 6
PHP;
46
47 6
        $this->filesystem->dumpFile($this->filePath, $code);
48 6
    }
49
}
50