TemplateCacheAsset   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 8
c 3
b 0
f 2
lcom 1
cbo 5
dl 0
loc 88
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A load() 0 8 1
A getLastModified() 0 16 4
A initialize() 0 10 2
1
<?php
2
3
namespace Hshn\AngularBundle\Assetic\Asset;
4
5
use Assetic\Asset\BaseAsset;
6
use Assetic\Filter\FilterInterface;
7
use Hshn\AngularBundle\TemplateCache\Compiler;
8
use Hshn\AngularBundle\TemplateCache\ConfigurationInterface;
9
use Hshn\AngularBundle\TemplateCache\TemplateFinder;
10
use Symfony\Component\Finder\SplFileInfo;
11
12
class TemplateCacheAsset extends BaseAsset
13
{
14
    /**
15
     * @var \Hshn\AngularBundle\TemplateCache\TemplateFinder
16
     */
17
    private $templateFinder;
18
19
    /**
20
     * @var \Hshn\AngularBundle\TemplateCache\Compiler
21
     */
22
    private $compiler;
23
24
    /**
25
     * @var \Hshn\AngularBundle\TemplateCache\ConfigurationInterface
26
     */
27
    private $configuration;
28
29
    /**
30
     * @var bool
31
     */
32
    private $initialized;
33
34
    /**
35
     * @var SplFileInfo[]
36
     */
37
    private $templates;
38
39
    /**
40
     * @param TemplateFinder         $templateFinder
41
     * @param Compiler               $compiler
42
     * @param ConfigurationInterface $configuration
43
     */
44
    public function __construct(TemplateFinder $templateFinder, Compiler $compiler, ConfigurationInterface $configuration)
45
    {
46
        parent::__construct();
47
48
        $this->templateFinder = $templateFinder;
49
        $this->compiler = $compiler;
50
        $this->configuration = $configuration;
51
        $this->initialized = false;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function load(FilterInterface $additionalFilter = null)
58
    {
59
        $this->initialize();
60
61
        $output = $this->compiler->compile($this->templates, $this->configuration->getName(), $this->configuration->getCreate());
62
63
        $this->doLoad($output, $additionalFilter);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getLastModified()
70
    {
71
        $this->initialize();
72
73
        $lastModified = null;
74
75
        foreach ($this->templates as $template) {
76
            if ($lastModified === null) {
77
                $lastModified = $template->getMTime();
78
            } elseif ($lastModified < $template->getMTime()) {
79
                $lastModified = $template->getMTime();
80
            }
81
        }
82
83
        return $lastModified;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    private function initialize()
90
    {
91
        if ($this->initialized) {
92
            return;
93
        }
94
95
        $this->initialized = true;
96
97
        $this->templates = $this->templateFinder->find($this->configuration);
98
    }
99
}
100