carno-php /
cache
| 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
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
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
Loading history...
|
|||||
| 37 | return yield $this->read($key); |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 38 | } else { |
||||
| 39 | yield $this->write($key, $dat = yield $getter()); |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 40 | return $dat; |
||||
| 41 | } |
||||
| 42 | } |
||||
| 43 | } |
||||
| 44 | } |
||||
| 45 |