Storage::remove()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Storage API
4
 * User: moyo
5
 * Date: 24/10/2017
6
 * Time: 12:13 PM
7
 */
8
9
namespace Carno\Cache\Chips;
10
11
use Carno\Cache\Contracts\Storing;
12
13
trait Storage
14
{
15
    /**
16
     * @var Storing
17
     */
18
    private $backend = null;
19
20
    /**
21
     * @param string $key
22
     * @return bool
23
     */
24
    final public function has(string $key)
25
    {
26
        return yield $this->backend->has($this->key($key));
0 ignored issues
show
Bug introduced by
It seems like key() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        return yield $this->backend->has($this->/** @scrutinizer ignore-call */ key($key));
Loading history...
Bug Best Practice introduced by
The expression yield $this->backend->has($this->key($key)) returns the type Generator which is incompatible with the documented return type boolean.
Loading history...
27
    }
28
29
    /**
30
     * @param string $key
31
     * @return mixed|null
32
     */
33
    final public function read(string $key)
34
    {
35
        return (false !== $got = yield $this->backend->read($this->key($key))) ? $got : null;
36
    }
37
38
    /**
39
     * @param string $key
40
     * @param mixed $data
41
     * @param int $ttl
42
     * @return bool
43
     */
44
    final public function write(string $key, $data, int $ttl = null)
45
    {
46
        return yield $this->backend->write($this->key($key), $data, $ttl ?? $this->ttl);
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->backend->wr...ta, $ttl ?? $this->ttl) returns the type Generator which is incompatible with the documented return type boolean.
Loading history...
47
    }
48
49
    /**
50
     * @param string $key
51
     * @return bool
52
     */
53
    final public function remove(string $key)
54
    {
55
        return yield $this->backend->remove($this->key($key));
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->backend->remove($this->key($key)) returns the type Generator which is incompatible with the documented return type boolean.
Loading history...
56
    }
57
}
58