Passed
Pull Request — master (#138)
by
unknown
03:22
created

Flysystem2Storage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 52
loc 52
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A fetch() 15 15 3
A save() 4 4 1
A delete() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kevinrob\GuzzleCache\Storage;
4
5
use Kevinrob\GuzzleCache\CacheEntry;
6
use League\Flysystem\Local\LocalFilesystemAdapter;
7
use League\Flysystem\Filesystem;
8
use League\Flysystem\FileNotFoundException;
9
10 View Code Duplication
class Flysystem2Storage implements CacheStorageInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
13
    /**
14
     * @var Filesystem
15
     */
16
    protected $filesystem;
17
18
    public function __construct(LocalFilesystemAdapter $adapter)
19
    {
20
        $this->filesystem = new Filesystem($adapter);
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function fetch($key)
27
    {
28
        if ($this->filesystem->fileExists($key)) {
29
            // The file exist, read it!
30
            $data = @unserialize(
31
                $this->filesystem->read($key)
32
            );
33
34
            if ($data instanceof CacheEntry) {
35
                return $data;
36
            }
37
        }
38
39
        return;
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function save($key, CacheEntry $data)
46
    {
47
        return $this->filesystem->write($key, serialize($data));
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function delete($key)
54
    {
55
        try {
56
            return $this->filesystem->delete($key);
57
        } catch (FileNotFoundException $ex) {
58
            return true;
59
        }
60
    }
61
}
62