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

ApcWrapper::store()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
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