FileCacheDriver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 48
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A remove() 0 3 1
A add() 0 5 1
A get() 0 5 1
1
<?php
2
3
namespace MidasSoft\DominicanBankParser\Cache;
4
5
class FileCacheDriver extends AbstractCacheDriver
6
{
7
    /**
8
     * The config of the driver.
9
     *
10
     * @var array
11
     */
12
    protected $config = [
13
        'path'     => '',
14
        'timezone' => 'America/Santo_Domingo',
15
    ];
16
17
    /**
18
     * Creates a new FileCacheDriver instance.
19
     *
20
     * @param array $config
21
     */
22 4
    public function __construct(array $config)
23
    {
24 4
        $this->config = $config;
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 4
    public function add($key, $value)
31
    {
32 4
        $filename = sprintf('%s/%s.txt', $this->config['path'], $key);
33 4
        $file = file_put_contents($filename, serialize($value));
0 ignored issues
show
Unused Code introduced by
The assignment to $file is dead and can be removed.
Loading history...
34 4
        $this->keys[] = $key;
35 4
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function get($key)
41
    {
42 1
        $filename = sprintf('%s/%s.txt', $this->config['path'], $key);
43
44 1
        return unserialize(file_get_contents($filename));
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 1
    public function remove($key)
51
    {
52 1
        unlink(sprintf('%s/%s.txt', $this->config['path'], $key));
53 1
    }
54
}
55