CommentsTokenParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTag() 0 3 1
A decideCommentsEnd() 0 3 1
A parse() 0 12 1
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 extended.
6
 *
7
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @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...
9
 */
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...
10
11
namespace nystudio107\templatecomments\web\twig\tokenparsers;
12
13
use nystudio107\templatecomments\web\twig\nodes\CommentsNode;
14
use Twig\Token;
15
use Twig\TokenParser\AbstractTokenParser;
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 CommentsTokenParser extends AbstractTokenParser
23
{
24
    // Public Methods
25
    // =========================================================================
26
27
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
28
     * @inheritdoc
29
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
30
    public function getTag()
31
    {
32
        return 'comments';
33
    }
34
35
    /**
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...
36
     * @inheritdoc
37
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
38
    public function parse(Token $token)
39
    {
40
        $lineno = $token->getLine();
41
        $stream = $this->parser->getStream();
42
        $nodes = [
43
            'templateName' => $this->parser->getExpressionParser()->parseExpression(),
44
        ];
45
        $stream->expect(Token::BLOCK_END_TYPE);
46
        $nodes['body'] = $this->parser->subparse([$this, 'decideCommentsEnd'], true);
47
        $stream->expect(Token::BLOCK_END_TYPE);
48
49
        return new CommentsNode($nodes, [], $lineno, $this->getTag());
50
    }
51
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
     * @param Token $token
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
55
     *
56
     * @return bool
57
     */
58
    public function decideCommentsEnd(Token $token): bool
59
    {
60
        return $token->test('endcomments');
61
    }
62
}
63