Test Failed
Push — master ( 21e806...ed25dd )
by Fran
05:25 queued 02:04
created

AssetsNode   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 0
cts 19
cp 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A compile() 0 28 2
1
<?php
2
3
namespace PSFS\base\extension;
4
/**
5
 * Class AssetsNode
6
 * @package PSFS\base\extension
7
 */
8
class AssetsNode extends \Twig_Node
9
{
10
11
    protected $hash;
12
    protected $type;
13
14
    /**
15
     * @param string $name
16
     * @param array $values
17
     * @param int $line
18
     * @param null $tag
19
     * @param string $type
20
     */
21
    public function __construct($name, $values, $line, $tag = null, $type = 'js')
22
    {
23
        parent::__construct(array('scripts' => $values["node"]), array('name' => $name), $line, $tag);
24
        $this->hash = $values["hash"];
25
        $this->type = $type;
26
    }
27
28
    public function compile(\Twig_Compiler $compiler)
29
    {
30
        $scripts = $this->getNode("scripts");
31
32
        //Creamos el parser
33
        $compiler->addDebugInfo($scripts)->write('$parser = new \\PSFS\\base\\extension\\AssetsParser(\'' . $this->type . '\')')
34
            ->raw(";\n");
35
36
        //Asociamos el hash
37
        $compiler->write('$parser->setHash(\'' . $this->hash . '\')')
38
            ->raw(";\n");
39
40
        //Asociamos los ficheros
41
        foreach ($scripts->getAttribute("value") as $value) {
42
            $compiler->write('$parser->addFile(\'' . $value . '\')')->raw(";\n");
43
        }
44
45
        //Procesamos los ficheros
46
        $compiler->write('$parser->compile()')
47
            ->raw(";\n");
48
49
        //Imprimimos los tags
50
        $compiler->write('$parser->printHtml()')
51
            ->raw(";\n");
52
53
        //Damos oxigeno
54
        $compiler->raw("\n");
55
    }
56
}
57