MinifyNode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 22
c 2
b 0
f 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 26 4
1
<?php
2
/**
3
 * Minify plugin for Craft CMS
4
 *
5
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
6
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
7
 * @license   MIT License https://opensource.org/licenses/MIT
8
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
9
10
namespace nystudio107\minify\twigextensions;
11
12
use nystudio107\minify\Minify;
13
use Twig\Compiler;
14
use Twig\Node\Node;
15
16
/**
17
 * Minify twig node parser
18
 *
19
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Minify
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.2.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
class MinifyNode extends Node
24
{
25
    // Public Methods
26
    // =========================================================================
27
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @param Compiler $compiler
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
30
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
31
    public function compile(Compiler $compiler): void
32
    {
33
        $html = $this->getAttribute('html');
34
        $css = $this->getAttribute('css');
35
        $js = $this->getAttribute('js');
36
37
        $compiler
38
            ->addDebugInfo($this);
39
40
        $compiler
41
            ->write("ob_start();\n")
42
            ->subcompile($this->getNode('body'))
43
            ->write("\$_compiledBody = ob_get_clean();\n");
44
45
        if ($html) {
46
            $compiler
47
                ->write("echo " . Minify::class . "::\$plugin->minify->htmlMin(\$_compiledBody);\n");
48
        } elseif ($css) {
49
            $compiler
50
                ->write("echo " . Minify::class . "::\$plugin->minify->cssMin(\$_compiledBody);\n");
51
        } elseif ($js) {
52
            $compiler
53
                ->write("echo " . Minify::class . "::\$plugin->minify->jsMin(\$_compiledBody);\n");
54
        } else {
55
            $compiler
56
                ->write("echo " . Minify::class . "::\$plugin->minify->minify(\$_compiledBody);\n");
57
        }
58
    }
59
}
60