Completed
Push — master ( e3c765...0c53bc )
by Nikola
03:19
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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A warmUp() 0 10 3
A isOptional() 0 4 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