FileResource   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A isFresh() 0 4 1
A getContent() 0 11 2
A __toString() 0 4 1
A getTemplate() 0 8 2
1
<?php
2
3
namespace Goetas\TwitalBundle\Assetic\Factory;
4
5
use Assetic\Factory\Resource\ResourceInterface;
6
use Symfony\Component\Templating\Loader\LoaderInterface;
7
use Symfony\Component\Templating\TemplateReference;
8
9
class FileResource implements ResourceInterface
10
{
11
    protected $loader;
12
13
    protected $path;
14
15
    protected $baseDir;
16
17
    protected $template;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param LoaderInterface $loader The templating loader
23
     * @param string $baseDir The directory
24
     * @param string $path The file path
25
     */
26
    public function __construct(LoaderInterface $loader, $baseDir, $path)
27
    {
28
        $this->loader = $loader;
29
        $this->baseDir = $baseDir;
30
        $this->path = $path;
31
    }
32
33
    public function isFresh($timestamp)
34
    {
35
        return $this->loader->isFresh($this->getTemplate(), $timestamp);
36
    }
37
38
    public function getContent()
39
    {
40
        $templateReference = $this->getTemplate();
41
        $fileResource = $this->loader->load($templateReference);
42
43
        if (!$fileResource) {
44
            throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', $templateReference));
45
        }
46
47
        return $fileResource->getContent();
48
    }
49
50
    public function __toString()
51
    {
52
        return (string)$this->getTemplate();
53
    }
54
55
    protected function getTemplate()
56
    {
57
        if (null === $this->template) {
58
            $this->template = new TemplateReference($this->path, 'twital');
59
        }
60
61
        return $this->template;
62
    }
63
}
64