FlySystemStorage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 72
loc 72
ccs 0
cts 28
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A get() 8 8 2
A has() 4 4 1
A set() 4 4 1
A remove() 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 SvImages\Cache;
4
5
use League\Flysystem\FileNotFoundException;
6
use League\Flysystem\Filesystem;
7
8
/**
9
 * @author Vytautas Stankus <[email protected]>
10
 * @license MIT
11
 */
12 View Code Duplication
class FlySystemStorage implements StorageInterface
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...
13
{
14
    /**
15
     * @var Filesystem
16
     */
17
    private $filesystem;
18
19
    /**
20
     * @param Filesystem $filesystem
21
     */
22
    public function __construct(Filesystem $filesystem)
23
    {
24
        $this->filesystem = $filesystem;
25
    }
26
27
    /**
28
     * Returns the value for a key.
29
     *
30
     * @param string $key A unique key
31
     *
32
     * @return string|false The file contents or false on failure.
33
     */
34
    public function get($key)
35
    {
36
        try {
37
            return $this->filesystem->read($key);
38
        } catch (FileNotFoundException $exception) {
39
            return false;
40
        }
41
    }
42
43
    /**
44
     * Checks if the cache has a value for a key.
45
     *
46
     * @param string $key A unique key
47
     *
48
     * @return Boolean Whether the cache has a value for this key
49
     */
50
    public function has($key)
51
    {
52
        return $this->filesystem->has($key);
53
    }
54
55
    /**
56
     * Sets a value in the cache.
57
     *
58
     * @param string $key      A unique key
59
     * @param string $contents The value to cache
60
     *
61
     * @return bool True on success, false on failure.
62
     */
63
    public function set($key, $contents)
64
    {
65
        $this->filesystem->put($key, $contents);
66
    }
67
68
    /**
69
     * Removes a value from the cache.
70
     *
71
     * @param string $key A unique key
72
     *
73
     * @return bool True on success, false on failure.
74
     */
75
    public function remove($key)
76
    {
77
        try {
78
            return $this->filesystem->delete($key);
79
        } catch (FileNotFoundException $exception) {
80
            return false;
81
        }
82
    }
83
}
84