TemplateEngine   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setTemplate() 0 15 2
A getSelectedTemplatePath() 0 3 1
A getPartialCacheStore() 0 9 2
1
<?php
2
3
namespace LeKoala\DebugBar\View;
4
5
use LeKoala\DebugBar\Proxy\CacheProxy;
0 ignored issues
show
Bug introduced by
The type LeKoala\DebugBar\Proxy\CacheProxy was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Psr\SimpleCache\CacheInterface;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\TemplateEngine\SSTemplateEngine;
9
use SilverStripe\Versioned\Caching\VersionedCacheAdapter;
10
use SilverStripe\View\SSViewer;
11
use SilverStripe\View\ThemeResourceLoader;
12
13
class TemplateEngine extends SSTemplateEngine
14
{
15
    protected ?string $selectedTemplatePath;
16
17
    public function setTemplate(string|array $templateCandidates): static
18
    {
19
        parent::setTemplate($templateCandidates);
20
21
        $themes = SSViewer::get_themes();
22
23
        $cacheAdapter = ThemeResourceLoader::inst()->getCache();
24
        $cacheKey = 'findTemplate_' . md5(json_encode($templateCandidates) . json_encode($themes));
25
26
        // Look for a cached result for this data set
27
        if ($cacheAdapter->has($cacheKey)) {
28
            $this->selectedTemplatePath = $cacheAdapter->get($cacheKey);
29
        }
30
31
        return $this;
32
    }
33
34
    public function getSelectedTemplatePath(): ?string
35
    {
36
        return $this->selectedTemplatePath;
37
    }
38
39
    public function getPartialCacheStore(): CacheInterface
40
    {
41
        $cache = parent::getPartialCacheStore();
42
43
        if (method_exists($cache, 'setContext')) {
44
            $cache->setContext(CacheProxy::CONTEXT_TMP);
45
        }
46
47
        return $cache;
48
    }
49
}
50