ConfigManifestProxy   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
c 2
b 0
f 0
dl 0
loc 88
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setTrackEmpty() 0 4 1
A getTrackEmpty() 0 3 1
A getConfigCalls() 0 3 1
A __construct() 0 10 1
A get() 0 17 4
1
<?php
2
3
namespace LeKoala\DebugBar\Proxy;
4
5
use LeKoala\DebugBar\DebugBar;
6
use SilverStripe\Config\Collections\CachedConfigCollection;
7
8
class ConfigManifestProxy extends CachedConfigCollection implements ProxyConfigCollectionInterface
9
{
10
    /**
11
     * @var CachedConfigCollection
12
     */
13
    protected $parent;
14
15
    /**
16
     * @var array
17
     */
18
    protected $configCalls = [];
19
20
    /**
21
     * @var boolean
22
     */
23
    protected $trackEmpty = false;
24
25
    /**
26
     * @param CachedConfigCollection $parent
27
     */
28
    public function __construct(CachedConfigCollection $parent)
29
    {
30
        $this->parent = $parent;
31
32
        $this->collection = $this->parent->getCollection();
33
        $this->cache = $this->parent->getCache();
34
        $this->flush = $this->parent->getFlush();
35
        $this->collectionCreator = $this->parent->getCollectionCreator();
36
37
        $this->setTrackEmpty(DebugBar::config()->config_track_empty);
38
    }
39
40
    /**
41
     * Monitor calls made to get configuration during a request
42
     *
43
     * {@inheritDoc}
44
     */
45
    public function get($class, $name = null, $excludeMiddleware = 0)
46
    {
47
        $result = parent::get($class, $name, $excludeMiddleware);
48
49
        // Only track not empty values by default
50
        if ($result || $this->trackEmpty) {
51
            if (!isset($this->configCalls[$class][$name])) {
52
                $this->configCalls[$class][$name] = [
53
                    'calls' => 0,
54
                    'result' => null
55
                ];
56
            }
57
            $this->configCalls[$class][$name]['calls']++;
58
            $this->configCalls[$class][$name]['result'] = $result;
59
        }
60
61
        return $result;
62
    }
63
64
    /**
65
     * Return a list of all config calls made during the request, including how many times they were called
66
     * and the result
67
     *
68
     * @return array
69
     */
70
    public function getConfigCalls()
71
    {
72
        return $this->configCalls;
73
    }
74
75
    /**
76
     * Get the value of trackEmpty
77
     *
78
     * @return boolean
79
     */
80
    public function getTrackEmpty()
81
    {
82
        return $this->trackEmpty;
83
    }
84
85
    /**
86
     * Set the value of trackEmpty
87
     *
88
     * @param boolean $trackEmpty
89
     *
90
     * @return self
91
     */
92
    public function setTrackEmpty($trackEmpty)
93
    {
94
        $this->trackEmpty = $trackEmpty;
95
        return $this;
96
    }
97
}
98