Cache::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/**
4
 *
5
 * This file is part of phpFastCache.
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For full copyright and license information, please see the docs/CREDITS.txt file.
10
 *
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 * @author PastisD https://github.com/PastisD
13
 * @author Alexander (asm89) <[email protected]>
14
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
15
 *
16
 */
17
declare(strict_types=1);
18
19
namespace Phpfastcache\Bundle\Twig\CacheExtension\TokenParser;
20
21
use Phpfastcache\Bundle\Twig\CacheExtension\Node\CacheNode;
22
23
/**
24
 * Parser for cache/endcache blocks.
25
 *
26
 * @author Alexander <[email protected]>
27
 */
28
class Cache extends \Twig_TokenParser
29
{
30
    /**
31
     * @param \Twig_Token $token
32
     *
33
     * @return boolean
34
     */
35
    public function decideCacheEnd(\Twig_Token $token)
36
    {
37
        return $token->test('endcache');
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function getTag()
44
    {
45
        return 'cache';
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function parse(\Twig_Token $token)
52
    {
53
        $lineno = $token->getLine();
54
        $stream = $this->parser->getStream();
55
56
        $annotation = $this->parser->getExpressionParser()->parseExpression();
57
58
        $key = $this->parser->getExpressionParser()->parseExpression();
59
60
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
61
        $body = $this->parser->subparse(array($this, 'decideCacheEnd'), true);
62
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
63
64
        return new CacheNode($annotation, $key, $body, $lineno, $this->getTag());
65
    }
66
}
67