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

EndTranslation::translate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
rs 10
cc 4
nc 4
nop 1
1
<?php
2
/**
3
 * @package Mailcode
4
 * @subpackage Translator
5
 */
6
7
declare(strict_types=1);
8
9
namespace Mailcode\Translator\Syntax\HubL;
10
11
use Mailcode\Mailcode_Commands_Command_End;
12
use Mailcode\Mailcode_Commands_Command_For;
13
use Mailcode\Mailcode_Commands_IfBase;
14
use Mailcode\Mailcode_Interfaces_Commands_PreProcessing;
15
use Mailcode\Mailcode_Translator_Command_End;
16
use Mailcode\Translator\Syntax\HubL;
17
18
/**
19
 * Translates the {@see Mailcode_Commands_Command_End} command to HubL.
20
 *
21
 * @package Mailcode
22
 * @subpackage Translator
23
 * @author Sebastian Mordziol <[email protected]>
24
 */
25
class EndTranslation extends HubL implements Mailcode_Translator_Command_End
26
{
27
    public function translate(Mailcode_Commands_Command_End $command): string
28
    {
29
        $openCmd = $command->getOpeningCommand();
30
31
        // This ending command is tied to a preprocessing command: Since
32
        // we do not want to keep these, we return an empty string to strip
33
        // it out.
34
        if($openCmd instanceof Mailcode_Interfaces_Commands_PreProcessing) {
35
            return '';
36
        }
37
38
        if($openCmd instanceof Mailcode_Commands_Command_For) {
39
            return '{% endfor %}';
40
        }
41
42
        if($openCmd instanceof Mailcode_Commands_IfBase) {
43
            return '{% endif %}';
44
        }
45
46
        return '{# ! Unknown opening command for end command ! #}';
47
    }
48
}
49