Passed
Pull Request — master (#2133)
by Arnaud
09:42 queued 04:08
created

TwigCacheRuntimeLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 16
ccs 5
cts 6
cp 0.8333
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Renderer;
15
16
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
17
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
18
use Twig\Extra\Cache\CacheRuntime;
19
use Twig\RuntimeLoader\RuntimeLoaderInterface;
20
21
class TwigCacheRuntimeLoader implements RuntimeLoaderInterface
22
{
23
    protected string $cacheDir;
24
25 1
    public function __construct(string $cacheDir)
26
    {
27 1
        $this->cacheDir = $cacheDir;
28
    }
29
30 1
    public function load(string $class)
31
    {
32 1
        if (CacheRuntime::class === $class) {
33 1
            return new CacheRuntime(new TagAwareAdapter(new FilesystemAdapter(namespace: '_fragments', directory: $this->cacheDir)));
34
        }
35
36
        return null;
37
    }
38
}
39