Completed
Push — master ( e3c765...0c53bc )
by Nikola
03:19
created

QuerySourcesCacheWarmer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/*
3
 * This file is part of the QueryResourcesLoaderBundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\QueryResourcesLoader\Twig\CacheWarmer;
11
12
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
13
14
/**
15
 * Class QuerySourcesCacheWarmer
16
 *
17
 * Warms up queries cache.
18
 *
19
 * @package RunOpenCode\Bundle\QueryResourcesLoader\Twig\CacheWarmer
20
 */
21
class QuerySourcesCacheWarmer implements CacheWarmerInterface
22
{
23
    private $twig;
24
    private $iterator;
25
26 3
    public function __construct(\Twig_Environment $twig, \Traversable $iterator)
27
    {
28 3
        $this->twig = $twig;
29 3
        $this->iterator = $iterator;
30 3
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function warmUp($cacheDir)
36
    {
37 2
        foreach ($this->iterator as $template) {
38
            try {
39 2
                $this->twig->load($template);
40 2
            } catch (\Twig_Error $e) {
41
                // noop
42
            }
43
        }
44 2
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 1
    public function isOptional()
50
    {
51 1
        return true;
52
    }
53
}
54