Passed
Push — master ( 6c661c...e8275e )
by Sebastian
04:14
created

Mailcode_Translator_Syntax_ApacheVelocity_ShowNumber::translateFormat()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 15
rs 10
1
<?php
2
/**
3
 * File containing the {@see \Mailcode\Mailcode_Translator_Syntax_ApacheVelocity_ShowNumber} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Translator
7
 * @see \Mailcode\Mailcode_Translator_Syntax_ApacheVelocity_ShowNumber
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use AppUtils\ConvertHelper;
15
16
/**
17
 * Translates the "ShowNumber" command to Apache Velocity.
18
 *
19
 * @package Mailcode
20
 * @subpackage Translator
21
 * @author Sebastian Mordziol <[email protected]>
22
 */
23
class Mailcode_Translator_Syntax_ApacheVelocity_ShowNumber extends Mailcode_Translator_Syntax_ApacheVelocity implements Mailcode_Translator_Command_ShowNumber
24
{
25
    public function translate(Mailcode_Commands_Command_ShowNumber $command): string
26
    {
27
        $template = "price.format(%s, %s, '%s', '%s')";
28
29
        $varName = ltrim($command->getVariableName(), '$');
30
        $formatInfo = $command->getFormatInfo();
31
32
        $statement = sprintf(
33
            $template,
34
            '$'.$varName,
35
            $formatInfo->getDecimals(),
36
            $formatInfo->getDecimalsSeparator(),
37
            $formatInfo->getThousandsSeparator()
38
        );
39
40
        if($command->isURLEncoded())
41
        {
42
            return sprintf(
43
                '${esc.url($%s)}',
44
                $statement
45
            );
46
        }
47
48
        return sprintf(
49
            '${%s}',
50
            $statement
51
        );
52
    }
53
}
54