Passed
Push — master ( d8dc61...dfdb64 )
by Sebastian
09:05
created

ShowPhoneTranslation   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 9
c 0
b 0
f 0
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A translate() 0 14 1
1
<?php
2
/**
3
 * @package Mailcode
4
 * @subpackage Translator
5
 */
6
7
declare(strict_types=1);
8
9
namespace Mailcode\Translator\Syntax\ApacheVelocity;
10
11
use Mailcode\Mailcode_Commands_Command_ShowPhone;
12
use Mailcode\Mailcode_Translator_Command_ShowPhone;
13
use Mailcode\Translator\Syntax\ApacheVelocity;
14
use function Mailcode\dollarize;
15
use function Mailcode\undollarize;
16
17
/**
18
 * Translates the {@see Mailcode_Commands_Command_ShowPhone} command to Apache Velocity.
19
 *
20
 * @package Mailcode
21
 * @subpackage Translator
22
 * @author Sebastian Mordziol <[email protected]>
23
 */
24
class ShowPhoneTranslation extends ApacheVelocity implements Mailcode_Translator_Command_ShowPhone
25
{
26
    public function translate(Mailcode_Commands_Command_ShowPhone $command): string
27
    {
28
        $template = "phone.e164(%s, '%s')";
29
30
        $varName = undollarize($command->getVariableName());
31
        $format = $command->getSourceFormat();
32
33
        $statement = sprintf(
34
            $template,
35
            dollarize($varName),
36
            $format
37
        );
38
39
        return $this->renderVariableEncodings($command, $statement);
40
    }
41
}
42