Completed
Push — develop ( 66c29c...10a2c8 )
by Stan
02:47
created

ApcWrapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 5 2
A flush() 0 5 2
A __construct() 0 3 1
A get() 0 5 2
1
<?php
2
3
namespace Krenor\Prometheus\Storage\Repositories;
4
5
class ApcWrapper
6
{
7
    /**
8
     * @var bool
9
     */
10
    protected $apcu = false;
11
12
    /**
13
     * Create a new APC wrapper instance.
14
     *
15
     * @return void
16
     */
17
    public function __construct()
18
    {
19
        $this->apcu = function_exists('apcu_fetch');
20
    }
21
22
    /**
23
     * @param string $key
24
     *
25
     * @return mixed
26
     */
27
    public function get(string $key)
28
    {
29
        return $this->apcu
30
            ? apcu_fetch($key)
31
            : apc_fetch($key);
32
    }
33
34
    /**
35
     * @param string $key
36
     * @param mixed $value
37
     *
38
     * @return bool
39
     */
40
    public function store(string $key, $value): bool
41
    {
42
        return $this->apcu
43
            ? apcu_store($key, $value)
44
            : apc_store($key, $value);
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    public function flush(): bool
51
    {
52
        return $this->apcu
53
            ? apcu_clear_cache()
54
            : apc_clear_cache('user');
55
    }
56
}
57