Test Failed
Push — master ( f51294...9c5f94 )
by Sebastian
03:08
created

getCommandTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Translator_Syntax_ApacheVelocity_ElseIf} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Translator
7
 * @see Mailcode_Translator_Syntax_ApacheVelocity_ElseIf
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Translates the "ElseIf" command to Apache Velocity.
16
 *
17
 * @package Mailcode
18
 * @subpackage Translator
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Translator_Syntax_ApacheVelocity_ElseIf extends Mailcode_Translator_Syntax_ApacheVelocity_Base_AbstractIf implements Mailcode_Translator_Command_ElseIf
22
{
23
    protected function getCommandTemplate() : string
24
    {
25
        return '#elseif(%s)';
26
    }
27
    
28
    public function translate(Mailcode_Commands_Command_ElseIf $command): string
29
    {
30
        return $this->_translate($command);
31
    }
32
    
33
    protected function translateBody(Mailcode_Commands_IfBase $command) : string
34
    {
35
        if($command instanceof Mailcode_Commands_Command_ElseIf_Command)
36
        {
37
            return $this->translateCommand($command);
38
        }
39
        
40
        if($command instanceof Mailcode_Commands_Command_ElseIf_Variable)
41
        {
42
            return $this->translateVariable($command);
43
        }
44
        
45
        if($command instanceof Mailcode_Commands_Command_ElseIf_Contains)
46
        {
47
            return $this->translateContains($command);
48
        }
49
        
50
        if($command instanceof Mailcode_Commands_Command_ElseIf_Empty)
51
        {
52
            return $this->translateEmpty($command);
53
        }
54
        
55
        if($command instanceof Mailcode_Commands_Command_ElseIf_NotEmpty)
56
        {
57
            return $this->translateNotEmpty($command);
58
        }
59
        
60
        return '';
61
    }
62
    
63
    protected function translateCommand(Mailcode_Commands_Command_ElseIf_Command $command) : string
64
    {
65
        return $this->_translateGeneric($command);
66
    }
67
    
68
    protected function translateVariable(Mailcode_Commands_Command_ElseIf_Variable $command) : string
69
    {
70
        return $this->_translateVariable(
71
            $command->getVariable(),
72
            $command->getComparator(),
73
            $command->getValue()
74
        );
75
    }
76
    
77
    protected function translateContains(Mailcode_Commands_Command_ElseIf_Contains $command) : string
78
    {
79
        return $this->_translateContains(
80
            $command->getVariable(),
81
            $command->isCaseInsensitive(),
82
            $command->getSearchTerm()
83
        );
84
    }
85
    
86
    protected function translateEmpty(Mailcode_Commands_Command_ElseIf_Empty $command) : string
87
    {
88
        return $this->_translateEmpty($command->getVariable(), false);
89
    }
90
91
    protected function translateNotEmpty(Mailcode_Commands_Command_ElseIf_NotEmpty $command) : string
92
    {
93
        return $this->_translateEmpty($command->getVariable(), true);
94
    }
95
}
96