Completed
Push — master ( 14a525...bc69d0 )
by Iman
02:10
created

Cache   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeCacheKey() 0 4 1
B cacheResult() 0 22 5
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils;
4
5
6
class Cache
7
{
8
9
    /**
10
     * @param $arg
11
     * @param $widget
12
     * @return string
13
     */
14
    private function makeCacheKey($arg, $widget)
15
    {
16
        return md5(json_encode($arg, JSON_FORCE_OBJECT) . $widget->template . class_basename($widget));
17
    }
18
19
    function cacheResult($args, $phpCode, $widget)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
    {
21
        $key = $this->makeCacheKey($args,$widget);
22
23
        $cache = app('cache');
24
25
        if ($widget->cacheTags) {
26
            $cache = $cache->tags($widget->cacheTags);
27
        }
28
29
        if ($widget->cacheLifeTime > 0) {
30
            return $cache->remember($key, $widget->cacheLifeTime, $phpCode);
31
        }
32
33
        if ($widget->cacheLifeTime < 0) {
34
            return $cache->rememberForever($key, $phpCode);
35
        }
36
37
        if ($widget->cacheLifeTime === 0) {
38
            return $phpCode();
39
        }
40
    }
41
42
}