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

TwigCacheRuntimeLoader::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
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