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

GimmeTokenParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
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\GimmeNode;
18
19
/**
20
 * Parser for gimme/endgimme blocks.
21
 */
22 View Code Duplication
class GimmeTokenParser 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 decideCacheEnd(\Twig_Token $token)
30
    {
31
        return $token->test('endgimme');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getTag()
38
    {
39
        return 'gimme';
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
        $annotation = $this->parser->getExpressionParser()->parseAssignmentExpression();
51
        $parameters = null;
52
        if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
53
            $parameters = $this->parser->getExpressionParser()->parseExpression();
54
        }
55
56
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
57
        $body = $this->parser->subparse([$this, 'decideCacheEnd'], true);
58
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
59
60
        return new GimmeNode($annotation, $parameters, $body, $lineno, $this->getTag());
61
    }
62
}
63