Repository::remember()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Nip\Cache\Stores;
4
5
use Closure;
6
use Symfony\Component\Cache\Psr16Cache;
7
8
/**
9
 * Class Repository
10
 * @package Nip\Cache\Stores
11
 */
12
class Repository extends Psr16Cache
13
{
14
    /**
15
     * Get an item from the cache, or execute the given Closure and store the result.
16
     *
17
     * @param  string  $key
18
     * @param  \DateTimeInterface|\DateInterval|int|null  $ttl
19
     * @param  \Closure  $callback
20
     * @return mixed
21
     */
22
    public function remember($key, $ttl, Closure $callback)
23
    {
24
        if ($this->has($key)) {
25
            return $this->get($key);
26
        }
27
28
        $this->set($key, $value = $callback(), $ttl);
29
30
        return $value;
31
    }
32
}
33