FlashesTokenParser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
B parse() 0 27 4
A getTag() 0 4 1
A isEndTag() 0 4 1
1
<?php
2
3
namespace Knp\RadBundle\Twig;
4
5
use Twig_Token;
6
use Twig_TokenParser;
7
8
/**
9
 * Token parser for "flashes" tags
10
 */
11
class FlashesTokenParser extends Twig_TokenParser
12
{
13
    private $nodeFactory;
14
15
    public function __construct(FlashesNodeFactory $nodeFactory = null)
16
    {
17
        $this->nodeFactory = $nodeFactory ?: new FlashesNodeFactory;
18
    }
19
20
    public function parse(Twig_Token $token)
21
    {
22
        $stream     = $this->parser->getStream();
23
        $exprParser = $this->parser->getExpressionParser();
24
25
        $typesExpr = null;
26
        if (!$stream->test(Twig_Token::NAME_TYPE, 'using') && !$stream->test(Twig_Token::BLOCK_END_TYPE)) {
27
            $typesExpr = $exprParser->parseExpression();
28
        }
29
30
        $catalogExpr = null;
31
32
        if ($stream->test(Twig_Token::NAME_TYPE, 'using')) {
33
            $stream->expect(Twig_Token::NAME_TYPE, 'using');
34
            $stream->expect(Twig_Token::NAME_TYPE, 'catalog');
35
36
            $catalogExpr = $exprParser->parseExpression();
37
        }
38
39
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
40
41
        $body = $this->parser->subparse(array($this, 'isEndTag'), true);
42
43
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
44
45
        return $this->nodeFactory->createFlashesNode($typesExpr, $catalogExpr, $body, $token->getLine());
46
    }
47
48
    public function getTag()
49
    {
50
        return 'flashes';
51
    }
52
53
    public function isEndTag(Twig_Token $token)
54
    {
55
        return $token->test('endflashes');
56
    }
57
}
58