Completed
Push — master ( e90e68...49a516 )
by Marco
04:59 queued 02:33
created

Filesystem   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 49
loc 49
ccs 16
cts 20
cp 0.8
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isXattrSupported() 5 5 2
B __construct() 25 25 5
A getStats() 13 13 1

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 namespace Comodojo\SimpleCache\Providers;
2
3
use \Comodojo\Cache\Drivers\FilesystemXattr as FilesystemXattrDriver;
4
use \Comodojo\Cache\Drivers\FilesystemGhost as FilesystemGhostDriver;
5
use \Comodojo\Cache\Components\EnhancedCacheItemPoolStats;
6
use \Psr\Log\LoggerInterface;
7
use \Comodojo\Exception\SimpleCacheException;
8
use \Comodojo\Exception\InvalidSimpleCacheArgumentException;
9
use \Exception;
10
11
/**
12
 * Apcu provider
13
 *
14
 * @package     Comodojo Spare Parts
15
 * @author      Marco Giovinazzi <[email protected]>
16
 * @license     MIT
17
 *
18
 * LICENSE:
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
 * THE SOFTWARE.
27
 */
28
29 View Code Duplication
class Filesystem extends AbstractEnhancedProvider {
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...
30
31 19
    public function __construct($cache_folder, LoggerInterface $logger = null) {
32
33
        try {
34
35 19
            if ( empty($cache_folder) ) {
36
                throw new InvalidSimpleCacheArgumentException("Invalid or unspecified cache folder");
37
            }
38
39 19
            if ( $cache_folder[strlen($cache_folder) - 1] != "/" ) $cache_folder = "$cache_folder/";
40
41 19
            if ( self::isXattrSupported($cache_folder) ) {
42
                $this->driver = new FilesystemXattrDriver(['cache-folder'=>$cache_folder]);
43
            } else {
44 19
                $this->driver = new FilesystemGhostDriver(['cache-folder'=>$cache_folder]);
45
            }
46
47 19
            parent::__construct($logger);
48
49
        } catch (Exception $e) {
50
51
            throw new SimpleCacheException($e->getMessage());
52
53
        }
54
55 19
    }
56
57 1
    public function getStats() {
58
59 1
        $info = $this->driver->stats();
60
61 1
        return new EnhancedCacheItemPoolStats(
62 1
            $this->getId(),
63 1
            $this->driver->getName(),
64 1
            $this->getState(),
65
            $info,
66 1
            []
67
        );
68
69
    }
70
71 19
    protected static function isXattrSupported($folder) {
72
73 19
        return function_exists("xattr_supported") && xattr_supported($folder);
74
75
    }
76
77
}
78