ProfilerNode::compile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 13
rs 9.9
1
<?php
2
/**
3
 * Twig Profiler plugin for Craft CMS
4
 *
5
 * Twig Profiler allows you to profile sections of your Twig templates, and see
6
 * the resulting timings in the Yii2 Debug Toolbar
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\twigprofiler\twigextensions;
13
14
use nystudio107\twigprofiler\TwigProfiler;
15
use Twig\Compiler;
16
use Twig\Node\Node;
17
18
/**
19
 * Class ProfilerTokenParser
20
 *
21
 * @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...
22
 * @package   TwigProfiler
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
23
 * @since     1.0.1
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...
24
 */
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...
25
class ProfilerNode extends Node
26
{
27
    // Public Methods
28
    // =========================================================================
29
30
    /**
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...
31
     * @inheritdoc
32
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
33
    public function compile(Compiler $compiler): void
34
    {
35
        $profileName = $this->getNode('profile');
36
        if ($profileName !== null) {
37
            $profileName = $profileName->attributes['value'] ?? '';
38
            if (!empty($profileName)) {
39
                $compiler
40
                    ->addDebugInfo($this)
41
                    ->write(TwigProfiler::class . "::\$plugin->profile->begin('" . $profileName . "');\n")
42
                    ->indent()
43
                    ->subcompile($this->getNode('body'))
44
                    ->outdent()
45
                    ->write(TwigProfiler::class . "::\$plugin->profile->end('" . $profileName . "');\n");
46
            }
47
        }
48
    }
49
}
50