Filesystem   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 19
loc 95
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setStopwatch() 0 4 1
A setStopwatchTags() 0 4 1
A getStopwatchEvent() 0 10 2
A doFetch() 10 10 2
A doContains() 9 9 2
A doSave() 0 9 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
 * @author Mikhail Dolgov <[email protected]>
4
 * @date   09.03.2016 11:59
5
 */
6
7
namespace SilexPinbaProvider\Cache;
8
9
use Doctrine\Common\Cache\FilesystemCache;
10
use Intaro\PinbaBundle\Stopwatch\Stopwatch;
11
use Intaro\PinbaBundle\Stopwatch\StopwatchEvent;
12
13
class Filesystem extends FilesystemCache{
14
    /**
15
     * @var Stopwatch
16
     */
17
    protected $stopwatch;
18
    protected $stopwatchAdditionalTags = array();
19
20
    /**
21
     * @param Stopwatch $stopwatch
22
     */
23
    public function setStopwatch(Stopwatch $stopwatch)
24
    {
25
        $this->stopwatch = $stopwatch;
26
    }
27
28
    /**
29
     * @param array $tags
30
     */
31
    public function setStopwatchTags(array $tags)
32
    {
33
        $this->stopwatchAdditionalTags = $tags;
34
    }
35
36
    /**
37
     * @param $methodName
38
     * @return StopwatchEvent|null
39
     */
40
    protected function getStopwatchEvent($methodName)
41
    {
42
        if (!$this->stopwatch) {
43
            return null;
44
        }
45
        $tags = $this->stopwatchAdditionalTags;
46
        $tags['group'] = 'filesystem::' . $methodName;
47
48
        return $this->stopwatch->start($tags);
49
    }
50
51
52
    /**
53
     * Fetches an entry from the cache.
54
     *
55
     * @param string $id The id of the cache entry to fetch.
56
     *
57
     * @return mixed|false The cached data or FALSE, if no cache entry exists for the given id.
58
     */
59 View Code Duplication
    protected function doFetch($id)
0 ignored issues
show
Duplication introduced by
This method 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...
60
    {
61
        $e = $this->getStopwatchEvent(__FUNCTION__);
62
        $result = parent::doFetch($id);
63
        if ($e) {
64
            $e->stop();
65
        }
66
67
        return $result;
68
    }
69
70
    /**
71
     * Tests if an entry exists in the cache.
72
     *
73
     * @param string $id The cache id of the entry to check for.
74
     *
75
     * @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise.
76
     */
77 View Code Duplication
    protected function doContains($id)
0 ignored issues
show
Duplication introduced by
This method 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...
78
    {
79
        $e = $this->getStopwatchEvent(__FUNCTION__);
80
        $result = parent::doContains($id);
81
        if ($e) {
82
            $e->stop();
83
        }
84
        return $result;
85
    }
86
87
    /**
88
     **
89
     * Puts data into the cache.
90
     *
91
     * @param string $id       The cache id.
92
     * @param string $data     The cache entry/data.
93
     * @param int    $lifeTime The lifetime. If != 0, sets a specific lifetime for this
94
     *                           cache entry (0 => infinite lifeTime).
95
     *
96
     * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
97
     */
98
    protected function doSave($id, $data, $lifeTime = 0)
99
    {
100
        $e = $this->getStopwatchEvent(__FUNCTION__);
101
        $result = parent::doSave($id, $data, $lifeTime);
102
        if ($e) {
103
            $e->stop();
104
        }
105
        return $result;
106
    }
107
}