Apcu   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 3 1
A write() 0 3 1
A read() 0 3 1
A has() 0 3 1
1
<?php
2
/**
3
 * Apcu storing (shared memory)
4
 * User: moyo
5
 * Date: 2018/7/11
6
 * Time: 10:41 AM
7
 */
8
9
namespace Carno\Cache\Stores;
10
11
use Carno\Cache\Contracts\Storing;
12
13
class Apcu implements Storing
14
{
15
    /**
16
     * @param string $key
17
     * @return bool
18
     */
19
    public function has(string $key) : bool
20
    {
21
        return apcu_exists($key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return apcu_exists($key) could return the type string[] which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    /**
25
     * @param string $key
26
     * @return mixed
27
     */
28
    public function read(string $key)
29
    {
30
        return apcu_fetch($key);
31
    }
32
33
    /**
34
     * @param string $key
35
     * @param mixed $data
36
     * @param int $ttl
37
     * @return bool
38
     */
39
    public function write(string $key, $data, int $ttl = null) : bool
40
    {
41
        return apcu_store($key, $data, $ttl ?? 0);
0 ignored issues
show
Bug Best Practice introduced by
The expression return apcu_store($key, $data, $ttl ?? 0) could return the type array which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
42
    }
43
44
    /**
45
     * @param string $key
46
     * @return bool
47
     */
48
    public function remove(string $key) : bool
49
    {
50
        return apcu_delete($key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return apcu_delete($key) could return the type string[] which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
51
    }
52
}
53