Passed
Push — master ( d8c2a1...59198c )
by Kevin
07:55
created

FlysystemStorage::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Kevinrob\GuzzleCache\Storage;
4
5
use Kevinrob\GuzzleCache\CacheEntry;
6
use League\Flysystem\AdapterInterface;
7
use League\Flysystem\Filesystem;
8
9
class FlysystemStorage implements CacheStorageInterface
10
{
11
12
    /**
13
     * @var Filesystem
14
     */
15
    protected $filesystem;
16
17 2
    public function __construct(AdapterInterface $adapter)
18
    {
19 2
        $this->filesystem = new Filesystem($adapter);
20 2
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25 2
    public function fetch($key)
26
    {
27 2
        if ($this->filesystem->has($key)) {
28
            // The file exist, read it!
29 2
            $data = @unserialize(
30 2
                $this->filesystem->read($key)
31 2
            );
32
33 2
            if ($data instanceof CacheEntry) {
34 2
                return $data;
35
            }
36
        }
37
38
        return;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 2
    public function save($key, CacheEntry $data)
45
    {
46 2
        return $this->filesystem->put($key, serialize($data));
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function delete($key)
53
    {
54
        return $this->filesystem->delete($key);
55
    }
56
}
57