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

ApcWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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