Transchoice::compile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 23
ccs 0
cts 19
cp 0
crap 12
rs 9.8333
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