Completed
Push — master ( af310e...ca9412 )
by Nikola
05:51
created

QuerySourcesCacheWarmer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RunOpenCode\Bundle\QueryResourcesLoader\Twig\CacheWarmer;
6
7
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
8
use Twig\Environment;
9
use Twig\Error\Error;
10
11
/**
12
 * Warms up queries cache.
13
 */
14
final class QuerySourcesCacheWarmer implements CacheWarmerInterface
15
{
16
    private Environment $twig;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
18
    /**
19
     * @var iterable<string>
20
     */
21
    private iterable $iterator;
22
23
    /**
24
     * @param iterable<string> $iterator
25
     */
26 3
    public function __construct(Environment $twig, iterable $iterator)
27
    {
28 3
        $this->twig     = $twig;
29 3
        $this->iterator = $iterator;
30 3
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function warmUp(string $cacheDir): array
36
    {
37 2
        foreach ($this->iterator as $template) {
38
            try {
39 2
                $this->twig->load($template);
40 1
            } catch (Error $error) {
41
                // noop
42
            }
43
        }
44
45 2
        return [];
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function isOptional(): bool
52
    {
53 1
        return true;
54
    }
55
}
56