OptionalTokenParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 0
f 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTag() 0 3 1
A parse() 0 13 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Twig\TokenParser;
5
6
use Shoot\Shoot\Twig\Node\OptionalNode;
7
use Twig\Error\SyntaxError;
8
use Twig\Node\Node;
9
use Twig\Token;
10
use Twig\TokenParser\AbstractTokenParser;
11
12
/**
13
 * Parses optional tags in the token stream.
14
 *
15
 * @internal
16
 */
17
final class OptionalTokenParser extends AbstractTokenParser
18
{
19
    /**
20
     * @param Token $token
21
     *
22
     * @return Node
23
     *
24
     * @throws SyntaxError
25
     */
26 1
    public function parse(Token $token): Node
27
    {
28 1
        $stream = $this->parser->getStream();
29
30 1
        $stream->expect(Token::BLOCK_END_TYPE);
31
32
        $body = $this->parser->subparse(function (Token $token): bool {
33 1
            return $token->test('endoptional');
34 1
        }, true);
35
36 1
        $stream->expect(Token::BLOCK_END_TYPE);
37
38 1
        return new OptionalNode($body, $token->getLine(), $this->getTag());
39
    }
40
41
    /**
42
     * @return string
43
     */
44 7
    public function getTag(): string
45
    {
46 7
        return 'optional';
47
    }
48
}
49