Passed
Push — master ( 5af0f6...36a1fd )
by Gabriel
14:51
created

Repository::remember()   A

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
    /**
16
     * Get an item from the cache, or execute the given Closure and store the result.
17
     *
18
     * @param  string  $key
19
     * @param  \DateTimeInterface|\DateInterval|int|null  $ttl
20
     * @param  \Closure  $callback
21
     * @return mixed
22
     */
23
    public function remember($key, $ttl, Closure $callback)
24
    {
25
        if ($this->has($key)) {
26
            return $this->get($key);
27
        }
28
29
        $this->set($key, $value = $callback(), $ttl);
30
31
        return $value;
32
    }
33
}
34