Passed
Push — cache ( c1ece6...c9eef1 )
by Arnaud
03:56
created

TwigRuntimeLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A load() 0 7 2
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 TwigRuntimeLoader implements RuntimeLoaderInterface
22
{
23
    protected string $cacheDir;
24
25
    public function __construct(string $cacheDir)
26
    {
27
        $this->cacheDir = $cacheDir;
28
    }
29
30
    public function load(string $class)
31
    {
32
        if (CacheRuntime::class === $class) {
33
            return new CacheRuntime(new TagAwareAdapter(new FilesystemAdapter(namespace: '_fragments', directory: $this->cacheDir)));
34
        }
35
36
        return null;
37
    }
38
}
39