Delegate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A delegate() 0 14 4
1
<?php
2
/**
3
 * Automatic refresh delegate
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\Refreshing;
12
use Closure;
13
14
trait Delegate
15
{
16
    /**
17
     * @var Refreshing
18
     */
19
    private $refresher = null;
20
21
    /**
22
     * @param string $key
23
     * @param Closure $getter
24
     * @param int $refreshed
25
     * @return mixed
26
     */
27
    final public function delegate(string $key, Closure $getter, int $refreshed = 0)
28
    {
29
        if ($refreshed) {
30
            $key2 = $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

30
            /** @scrutinizer ignore-call */ 
31
            $key2 = $this->key($key);
Loading history...
31
            if ($this->refresher->has($key2)) {
32
                return yield $this->refresher->value($key2);
33
            }
34
            return yield $this->refresher->register($key2, $getter, $refreshed);
35
        } else {
36
            if (yield $this->has($key)) {
0 ignored issues
show
Bug introduced by
It seems like has() 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

36
            if (yield $this->/** @scrutinizer ignore-call */ has($key)) {
Loading history...
37
                return yield $this->read($key);
0 ignored issues
show
Bug introduced by
It seems like read() 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

37
                return yield $this->/** @scrutinizer ignore-call */ read($key);
Loading history...
38
            } else {
39
                yield $this->write($key, $dat = yield $getter());
0 ignored issues
show
Bug introduced by
It seems like write() 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

39
                yield $this->/** @scrutinizer ignore-call */ write($key, $dat = yield $getter());
Loading history...
40
                return $dat;
41
            }
42
        }
43
    }
44
}
45