Completed
Push — master ( b95763...2cb7d7 )
by Nikola
29:49
created

QuerySourcesCacheWarmer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 34
wmc 5
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A warmUp() 0 11 3
A isOptional() 0 4 1
1
<?php
2
3
namespace RunOpenCode\Bundle\QueryResourcesLoader\Twig\CacheWarmer;
4
5
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
6
7
class QuerySourcesCacheWarmer implements CacheWarmerInterface
8
{
9
    private $twig;
10
    private $iterator;
11
12
    public function __construct(\Twig_Environment $twig, \Traversable $iterator)
13
    {
14
        $this->twig = $twig;
15
        $this->iterator = $iterator;
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function warmUp($cacheDir)
22
    {
23
        foreach ($this->iterator as $template) {
24
            try {
25
                $this->twig->loadTemplate($template);
26
            } catch (\Twig_Error $e) {
27
                // problem during compilation, give up
28
                // might be a syntax error or a non-Twig template
29
            }
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function isOptional()
37
    {
38
        return true;
39
    }
40
}
41