Cache::getOriginalBackend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Cache
4
 *
5
 * @package CacheCheck\Domain\Model
6
 * @author  Tim Lochmüller
7
 */
8
9
namespace HDNET\CacheCheck\Domain\Model;
10
11
use HDNET\CacheCheck\Service\CacheRegistry;
12
use HDNET\CacheCheck\Service\KeyPerformanceIndicator;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
15
/**
16
 * Cache
17
 *
18
 * @author Tim Lochmüller
19
 */
20
class Cache
21
{
22
23
    /**
24
     * Name of the cache
25
     *
26
     * @var string
27
     */
28
    protected $name;
29
30
    /**
31
     * Frontend
32
     *
33
     * @var string
34
     */
35
    protected $frontend;
36
37
    /**
38
     * Backend
39
     *
40
     * @var string
41
     */
42
    protected $backend;
43
44
    /**
45
     * Original backend. If set, than the cache is in analysed mode
46
     *
47
     * @var string
48
     */
49
    protected $originalBackend;
50
51
    /**
52
     * Groups
53
     *
54
     * @var array
55
     */
56
    protected $groups;
57
58
    /**
59
     * Options
60
     *
61
     * @var array
62
     */
63
    protected $options;
64
65
    /**
66
     * String representation
67
     *
68
     * @return string
69
     */
70
    public function __toString()
71
    {
72
        return $this->getName();
73
    }
74
75
    /**
76
     * Get name
77
     *
78
     * @return string
79
     */
80
    public function getName()
81
    {
82
        return $this->name;
83
    }
84
85
    /**
86
     * Set name
87
     *
88
     * @param string $name
89
     */
90
    public function setName($name)
91
    {
92
        $this->name = $name;
93
    }
94
95
    /**
96
     * Get frontend
97
     *
98
     * @return string
99
     */
100
    public function getFrontend()
101
    {
102
        return $this->frontend;
103
    }
104
105
    /**
106
     * Set frontend
107
     *
108
     * @param string $frontend
109
     */
110
    public function setFrontend($frontend)
111
    {
112
        $this->frontend = $frontend;
113
    }
114
115
    /**
116
     * Get backend
117
     *
118
     * @return string
119
     */
120
    public function getBackend()
121
    {
122
        return $this->backend;
123
    }
124
125
    /**
126
     * Set backend
127
     *
128
     * @param string $backend
129
     */
130
    public function setBackend($backend)
131
    {
132
        $this->backend = $backend;
133
    }
134
135
    /**
136
     * get original backend
137
     *
138
     * @return string
139
     */
140
    public function getOriginalBackend()
141
    {
142
        return $this->originalBackend;
143
    }
144
145
    /**
146
     * set original backend
147
     *
148
     * @param string $originalBackend
149
     */
150
    public function setOriginalBackend($originalBackend)
151
    {
152
        $this->originalBackend = $originalBackend;
153
    }
154
155
    /**
156
     * get groups
157
     *
158
     * @return array
159
     */
160
    public function getGroups()
161
    {
162
        return $this->groups;
163
    }
164
165
    /**
166
     * set groups
167
     *
168
     * @param array $groups
169
     */
170
    public function setGroups($groups)
171
    {
172
        $this->groups = $groups;
173
    }
174
175
    /**
176
     * get options
177
     *
178
     * @return array
179
     */
180
    public function getOptions()
181
    {
182
        return $this->options;
183
    }
184
185
    /**
186
     * set options
187
     *
188
     * @param array $options
189
     */
190
    public function setOptions($options)
191
    {
192
        $this->options = $options;
193
    }
194
195
    /**
196
     * Check if the current cache is in analyse mode
197
     *
198
     * @return bool
199
     */
200
    public function getIsInAnalyseMode()
201
    {
202
        return trim($this->getOriginalBackend()) !== '';
203
    }
204
205
    /**
206
     * get static KPI
207
     *
208
     * @return array
209
     */
210
    public function getStaticKpi()
211
    {
212
        return KeyPerformanceIndicator::getInstance()
213
            ->getStatic($this);
214
    }
215
216
    /**
217
     * get dynamic KPI and cache the output in a runtime cache to speed
218
     * up the sorting of the caches in the SortService
219
     *
220
     * @return array
221
     */
222
    public function getDynamicKpi()
223
    {
224
        static $dynamicCache = [];
225
        if ($dynamicCache[$this->getName()]) {
226
            return $dynamicCache[$this->getName()];
227
        }
228
        $dynamicCache[$this->getName()] = KeyPerformanceIndicator::getInstance()
229
            ->getDynamic($this);
230
        return $dynamicCache[$this->getName()];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $dynamicCache[$this->getName()]; of type false|array adds false to the return on line 230 which is incompatible with the return type documented by HDNET\CacheCheck\Domain\Model\Cache::getDynamicKpi of type array. It seems like you forgot to handle an error condition.
Loading history...
231
    }
232
233
    /**
234
     * Get the real backend information
235
     *
236
     * @return string
237
     */
238
    public function getRealBackend()
239
    {
240
        if (trim($this->getOriginalBackend()) !== '') {
241
            return $this->getOriginalBackend();
242
        }
243
        return $this->getBackend();
244
    }
245
246
    /**
247
     * Checks if this cache is changeable
248
     *
249
     * @return bool
250
     */
251
    public function getIsChangeable()
252
    {
253
        $cacheRegistry = GeneralUtility::makeInstance(CacheRegistry::class);
254
        return !in_array($this->getName(), $cacheRegistry->getNonChangeableCaches());
255
    }
256
}
257