Completed
Push — master ( 856f7c...9f8837 )
by Robbie
01:36
created

PartialCacheCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A collect() 0 8 1
A getWidgets() 0 19 2
A getTemplateCache() 0 4 2
A addTemplateCache() 0 4 1
A setTemplateCache() 0 4 1
1
<?php
2
3
namespace LeKoala\DebugBar\Collector;
4
5
use DebugBar\DataCollector\DataCollector;
6
use DebugBar\DataCollector\Renderable;
7
8
/**
9
 * Collects data about the partial cache hits and misses during a SilverStripe request
10
 */
11
class PartialCacheCollector extends DataCollector implements Renderable
12
{
13
    /**
14
     * Contains a list of all partial caches found.
15
     * @var array
16
     */
17
    protected static $templateCache = [];
18
19
    public function getName()
20
    {
21
        return 'partial-cache';
22
    }
23
24
    public function collect()
25
    {
26
        $result = self::getTemplateCache();
27
        return [
28
            'count' => count($result),
29
            'calls' => $result
30
        ];
31
    }
32
33
    public function getWidgets()
34
    {
35
        $widgets = [
36
            'Partial Cache' => [
37
                'icon' => 'asterisk',
38
                'widget' => 'PhpDebugBar.Widgets.ConfigWidget',
39
                'map' => 'partial-cache.calls',
40
                'default' => '{}'
41
            ]
42
        ];
43
        if (count(self::getTemplateCache()) > 0) {
44
            $widgets['Partial Cache:badge'] = [
45
                'map' => 'partial-cache.count',
46
                'default' => 0
47
            ];
48
        }
49
50
        return $widgets;
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public static function getTemplateCache()
57
    {
58
        return (self::$templateCache) ?: [];
59
    }
60
61
    /**
62
     * Adds an item to the templateCache array
63
     * @param string $key
64
     * @param array $item
65
     */
66
    public static function addTemplateCache($key, $item)
67
    {
68
        self::$templateCache[$key] = $item;
69
    }
70
71
    /**
72
     * @param array $templateCache
73
     */
74
    public static function setTemplateCache($templateCache)
75
    {
76
        self::$templateCache = $templateCache;
77
    }
78
}
79