CssTokenParser::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Braunstetter\AssetsPushBundle\Twig\TokenParser;
4
5
use Braunstetter\AssetsPushBundle\Twig\Nodes\CssNode;
6
use Twig\Node\Node;
7
use Twig\Token;
8
use Twig\TokenParser\AbstractTokenParser;
9
10
class CssTokenParser extends AbstractTokenParser
11
{
12
13
    /**
14
     * @inheritDoc
15
     */
16
    public function parse(Token $token): Node|CssNode
17
    {
18
        $parser = $this->parser;
19
        $stream = $parser->getStream();
20
21
        $data = null;
22
23
        // keep collecting strings until the block ends
24
        while (!$stream->test(Token::BLOCK_END_TYPE)) {
25
            $data = $stream->expect(Token::STRING_TYPE)->getValue();
26
        }
27
28
        $stream->expect(Token::BLOCK_END_TYPE);
29
30
        return new CssNode($data, $token->getLine(), $this->getTag());
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function getTag(): string
37
    {
38
        return 'css';
39
    }
40
}