Completed
Push — master ( 49a516...79d061 )
by Marco
04:40
created

Filesystem::__construct()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 25
Code Lines 12

Duplication

Lines 25
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 6.2017

Importance

Changes 0
Metric Value
dl 25
loc 25
ccs 7
cts 11
cp 0.6364
rs 8.439
c 0
b 0
f 0
cc 5
eloc 12
nc 16
nop 2
crap 6.2017
1
<?php namespace Comodojo\Cache\Providers;
2
3
use \Comodojo\Cache\Drivers\FilesystemXattr as FilesystemXattrDriver;
4
use \Comodojo\Cache\Drivers\FilesystemGhost as FilesystemGhostDriver;
5
use \Comodojo\Cache\Item;
6
use \Comodojo\Cache\Components\EnhancedCacheItemPoolStats;
7
use \Psr\Log\LoggerInterface;
8
use \Comodojo\Exception\CacheException;
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 28
    public function __construct($cache_folder, LoggerInterface $logger = null) {
32
33
        try {
34
35 28
            if ( empty($cache_folder) ) {
36
                throw new InvalidCacheArgumentException("Invalid or unspecified cache folder");
37
            }
38
39 28
            if ( $cache_folder[strlen($cache_folder) - 1] != "/" ) $cache_folder = "$cache_folder/";
40
41 28
            if ( self::isXattrSupported($cache_folder) ) {
42
                $this->driver = new FilesystemXattrDriver(['cache-folder'=>$cache_folder]);
43
            } else {
44 28
                $this->driver = new FilesystemGhostDriver(['cache-folder'=>$cache_folder]);
45
            }
46
47 28
            parent::__construct($logger);
48
49
        } catch (Exception $e) {
50
51
            throw new CacheException($e->getMessage());
52
53
        }
54
55 28
    }
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 28
    protected static function isXattrSupported($folder) {
72
73 28
        return function_exists("xattr_supported") && xattr_supported($folder);
74
75
    }
76
77
}
78