Transchoice   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 23
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 23 3
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\Twig\Node;
13
14
use Twig\Compiler;
15
use Twig\Node\Expression\AbstractExpression;
16
use Twig\Node\Expression\ArrayExpression;
17
18
class Transchoice extends AbstractExpression
19
{
20
    public function __construct(ArrayExpression $arguments, $lineno)
21
    {
22
        parent::__construct(['arguments' => $arguments], [], $lineno);
23
    }
24
25
    public function compile(Compiler $compiler): void
26
    {
27
        $compiler->raw(
28
            \sprintf(
29
                '$this->env->getExtension(\'%s\')->%s(',
30
                'Translation\Bundle\Twig\TranslationExtension',
31
                'transchoiceWithDefault'
32
            )
33
        );
34
35
        $first = true;
36
        /** @var ArrayExpression $node */
37
        $node = $this->getNode('arguments');
38
        foreach ($node->getKeyValuePairs() as $pair) {
39
            if (!$first) {
40
                $compiler->raw(', ');
41
            }
42
            $first = false;
43
44
            $compiler->subcompile($pair['value']);
45
        }
46
47
        $compiler->raw(')');
48
    }
49
}
50