Completed
Push — master ( bf375b...cc5661 )
by Rafał
07:07
created

ContainerTokenParser::decideEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Templates System.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\TemplatesSystem\Twig\TokenParser;
16
17
use SWP\Component\TemplatesSystem\Twig\Node\ContainerNode;
18
19
/**
20
 * Parser for container/endcontainer blocks.
21
 */
22 View Code Duplication
class ContainerTokenParser extends \Twig_TokenParser
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    /**
25
     * @param \Twig_Token $token
26
     *
27
     * @return bool
28
     */
29
    public function decideEnd(\Twig_Token $token)
30
    {
31
        return $token->test('endcontainer');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getTag()
38
    {
39
        return 'container';
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function parse(\Twig_Token $token)
46
    {
47
        $lineno = $token->getLine();
48
        $stream = $this->parser->getStream();
49
50
        $name = $this->parser->getExpressionParser()->parseExpression();
51
52
        $parameters = null;
53
        if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
54
            $parameters = $this->parser->getExpressionParser()->parseExpression();
55
        }
56
57
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
58
        $body = $this->parser->subparse([$this, 'decideEnd'], true);
59
60
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
61
62
        return new ContainerNode($name, $parameters, $body, $lineno, $this->getTag());
63
    }
64
}
65