Conditions | 5 |
Paths | 10 |
Total Lines | 25 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 6.2499 |
Changes | 0 |
1 | <?php |
||
32 | 1 | public function lazy(callable $callable, $cacheKey, $duration = 86400, $dependency = null) |
|
33 | { |
||
34 | /** @var \yii\caching\Cache $owner */ |
||
35 | 1 | if (get_called_class() === LazyCache::className()) { |
|
36 | 1 | $owner = $this->owner; |
|
37 | 1 | } else { |
|
38 | $owner = $this; |
||
39 | } |
||
40 | 1 | $result = $owner->get($cacheKey); |
|
41 | 1 | if ($result === false) { |
|
42 | 1 | $result = call_user_func($callable); |
|
43 | |||
44 | 1 | if (is_string($dependency)) { |
|
45 | $dependency = [$dependency]; |
||
46 | } |
||
47 | 1 | if (is_array($dependency)) { |
|
48 | $dependency = new TagDependency([ |
||
49 | 'tags' => $dependency, |
||
50 | ]); |
||
51 | } |
||
52 | |||
53 | 1 | $owner->set($cacheKey, $result, $duration, $dependency); |
|
54 | 1 | } |
|
55 | 1 | return $result; |
|
56 | } |
||
57 | } |