CommentsNode   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 20
c 5
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 23 2
1
<?php
2
/**
3
 * Template Comments plugin for Craft CMS
4
 *
5
 * Adds a HTML comment to demarcate each Twig template that is included or
6
 * extended.
7
 *
8
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @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...
10
 */
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...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\templatecomments\web\twig\nodes;
13
14
use Twig\Compiler;
15
use Twig\Node\Node;
16
17
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
 * @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...
19
 * @package   TemplateComments
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
20
 * @since     1.0.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...
21
 */
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...
22
class CommentsNode extends Node
23
{
24
    // Public Methods
25
    // =========================================================================
26
27
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $compiler should have a doc-comment as per coding-style.
Loading history...
28
     * @inheritdoc
29
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
30
    public function compile(Compiler $compiler): void
31
    {
32
        $compiler
33
            ->addDebugInfo($this)
34
            ->write('$_templateTimer = microtime(true)')
35
            ->raw(";\n")
36
            ->write('$_templateName = ')
37
            ->subcompile($this->getNode('templateName'))
38
            ->raw(";\n")
39
            ->write('echo PHP_EOL."<!-- >>> TEMPLATE BEGIN >>> ".$_templateName." -->".PHP_EOL')
40
            ->raw(";\n");
41
        // Make sure there is a body node
42
        if (!empty($this->nodes['body'])) {
43
            $compiler
44
                ->indent()
45
                ->subcompile($this->getNode('body'))
46
                ->outdent();
47
        }
48
        $compiler
49
            ->write('echo PHP_EOL."<!-- <<< TEMPLATE END <<< FROM ".$_templateName." TIME ".number_format((microtime(true)-$_templateTimer)*1000,2)."ms -->".PHP_EOL')
50
            ->raw(";\n")
51
            ->write("unset(\$_templateName);\n")
52
            ->write("unset(\$_templateTimer);\n");
53
    }
54
}
55