Passed
Push — master ( 074e22...c7a4af )
by Oleg
03:48
created

WincacheDriver::decrement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php /** MicroWincacheDriver */
2
3
namespace Micro\Cache\Driver;
4
5
use Micro\Base\Exception;
6
use Micro\Base\IContainer;
7
8
/**
9
 * Class WincacheDriver
10
 *
11
 * @author Oleg Lunegov <[email protected]>
12
 * @link https://github.com/linpax/microphp-framework
13
 * @copyright Copyright &copy; 2013 Oleg Lunegov
14
 * @license /LICENSE
15
 * @package Micro
16
 * @subpackage Cache\Driver
17
 * @version 1.0
18
 * @since 1.0
19
 */
20
class WincacheDriver extends BaseCacheDriver
21
{
22
    /**
23
     * Constructor
24
     *
25
     * @access public
26
     *
27
     * @param IContainer $container
28
     * @param array $config array config
29
     *
30
     * @result void
31
     * @throws Exception
32
     */
33
    public function __construct(IContainer $container, array $config = [])
34
    {
35
        parent::__construct($container, $config);
36
37
        if (!$this->check()) {
38
            throw new Exception('Extension WinCache not installed');
39
        }
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function check()
46
    {
47
        return (!extension_loaded('wincache')) ? true : false;
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function get($name)
54
    {
55
        $success = false;
56
        $data = wincache_ucache_get($name, $success);
57
58
        return $success ? $data : false;
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function set($name, $value, $duration = 0)
65
    {
66
        return wincache_ucache_set($name, $value, $duration);
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function delete($name)
73
    {
74
        return wincache_ucache_delete($name);
75
    }
76
77
    /**
78
     * Clean all data from cache
79
     *
80
     * @access public
81
     * @return mixed
82
     */
83
    public function clean()
84
    {
85
        return wincache_ucache_clear();
86
    }
87
88
    /**
89
     * @inheritdoc
90
     */
91
    public function info()
92
    {
93
        return wincache_ucache_info(true);
94
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function getMeta($id)
100
    {
101
        if ($stored = wincache_ucache_info(false, $id)) {
102
            $age = $stored['ucache_entries'][1]['age_seconds'];
103
            $ttl = $stored['ucache_entries'][1]['ttl_seconds'];
104
            $hitCount = $stored['ucache_entries'][1]['hitcount'];
105
106
            return ['expire' => $ttl - $age, 'hitcount' => $hitCount, 'age' => $age, 'ttl' => $ttl];
107
        }
108
109
        return false;
110
    }
111
112
    /**
113
     * @inheritdoc
114
     */
115 View Code Duplication
    public function increment($name, $offset = 1)
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...
116
    {
117
        $success = false;
118
        $value = wincache_ucache_inc($name, $offset, $success);
119
120
        return ($success === true) ? $value : false;
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126 View Code Duplication
    public function decrement($name, $offset = 1)
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...
127
    {
128
        $success = false;
129
        $value = wincache_ucache_dec($name, $offset, $success);
130
131
        return ($success === true) ? $value : false;
132
    }
133
} 
134