SimpleCache   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 25
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieve() 0 4 1
1
<?php
2
3
namespace hamburgscleanest\DataTables\Models\Cache;
4
5
use Illuminate\Support\Collection;
6
7
/**
8
 * Class SimpleCache
9
 * @package hamburgscleanest\DataTables\Models\Cache
10
 */
11
class SimpleCache implements Cache {
12
13
    /** @var int */
14
    protected $_minutes;
15
    /** @var string */
16
    private $_key;
17
18
    /**
19
     * SimpleCache constructor.
20
     * @param int $minutes For how long should the data be cached?
21
     */
22 1
    public function __construct(int $minutes = 60)
23
    {
24 1
        $this->_minutes = $minutes;
25 1
        $this->_key = \md5(\sprintf('%s-%s', $minutes, \request()->url()));
26 1
    }
27
28
    /**
29
     * @param \Closure $dataFunction
30
     * @return Collection
31
     */
32
    public function retrieve(\Closure $dataFunction) : Collection
33
    {
34 1
        return \Illuminate\Support\Facades\Cache::remember($this->_key, $this->_minutes, function() use ($dataFunction) {
35 1
            return $dataFunction();
36 1
        });
37
    }
38
}