PathTokenParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 12 1
A __construct() 0 4 1
A getTag() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Twig\TokenParser;
15
16
use Sonata\MediaBundle\Twig\Node\PathNode;
17
use Twig\Token;
18
use Twig\TokenParser\AbstractTokenParser;
19
20
/**
21
 * @final since sonata-project/media-bundle 3.21.0
22
 */
23
class PathTokenParser extends AbstractTokenParser
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $extensionName;
29
30
    /**
31
     * @param string $extensionName
32
     */
33
    public function __construct($extensionName)
34
    {
35
        $this->extensionName = $extensionName;
36
    }
37
38
    public function parse(Token $token)
39
    {
40
        $media = $this->parser->getExpressionParser()->parseExpression();
41
42
        $this->parser->getStream()->next();
43
44
        $format = $this->parser->getExpressionParser()->parseExpression();
45
46
        $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
47
48
        return new PathNode($this->extensionName, $media, $format, $token->getLine(), $this->getTag());
49
    }
50
51
    public function getTag()
52
    {
53
        return 'path';
54
    }
55
}
56