Issues (172)

src/twigextensions/ProfilerTokenParser.php (22 issues)

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
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
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
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
21
 * @package   TwigProfiler
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
22
 * @since     1.0.1
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
23
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
24
class ProfilerTokenParser extends AbstractTokenParser
25
{
26
    // Public Methods
27
    // =========================================================================
28
29
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
30
     * @inheritdoc
31
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
32
    public function getTag(): string
33
    {
34
        return 'profile';
35
    }
36
37
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $token should have a doc-comment as per coding-style.
Loading history...
38
     * @inheritdoc
39
     */
0 ignored issues
show
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
Missing doc comment for function decideProfilerEnd()
Loading history...
55
    {
56
        return $token->test('endprofile');
57
    }
58
}
59