ProfilerTokenParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 11
c 4
b 0
f 0
dl 0
loc 33
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTag() 0 3 1
A parse() 0 12 1
A decideProfilerEnd() 0 3 1
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 Twig\Token;
15
use Twig\TokenParser\AbstractTokenParser;
16
17
/**
18
 * Class ProfilerTokenParser
19
 *
20
 * @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...
21
 * @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...
22
 * @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...
23
 */
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...
24
class ProfilerTokenParser extends AbstractTokenParser
25
{
26
    // Public Methods
27
    // =========================================================================
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @inheritdoc
31
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
32
    public function getTag(): string
33
    {
34
        return 'profile';
35
    }
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $token should have a doc-comment as per coding-style.
Loading history...
38
     * @inheritdoc
39
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
40
    public function parse(Token $token): ProfilerNode
41
    {
42
        $lineno = $token->getLine();
43
        $stream = $this->parser->getStream();
44
        $nodes = [
45
            'profile' => $this->parser->getExpressionParser()->parseExpression(),
46
        ];
47
        $stream->expect(Token::BLOCK_END_TYPE);
48
        $nodes['body'] = $this->parser->subparse(fn(Token $token): bool => $this->decideProfilerEnd($token), true);
49
        $stream->expect(Token::BLOCK_END_TYPE);
50
51
        return new ProfilerNode($nodes, [], $lineno, $this->getTag());
52
    }
53
54
    public function decideProfilerEnd(Token $token): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function decideProfilerEnd()
Loading history...
55
    {
56
        return $token->test('endprofile');
57
    }
58
}
59