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

Mailcode_Translator_Syntax_ApacheVelocity_If::_translateEmpty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Translator_Syntax_ApacheVelocity_If} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Translator
7
 * @see Mailcode_Translator_Syntax_ApacheVelocity_If
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Translates the "If" command to Apache Velocity.
16
 *
17
 * @package Mailcode
18
 * @subpackage Translator
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Translator_Syntax_ApacheVelocity_If extends Mailcode_Translator_Syntax_ApacheVelocity_Base_AbstractIf implements Mailcode_Translator_Command_If
22
{
23
    protected function getCommandTemplate() : string
24
    {
25
        return '#if(%s)';
26
    }
27
    
28
    public function translate(Mailcode_Commands_Command_If $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_If_Command)
36
        {
37
            return $this->translateCommand($command);
38
        }
39
        
40
        if($command instanceof Mailcode_Commands_Command_If_Variable)
41
        {
42
            return $this->translateVariable($command);
43
        }
44
        
45
        if($command instanceof Mailcode_Commands_Command_If_Contains)
46
        {
47
            return $this->translateContains($command);
48
        }
49
        
50
        if($command instanceof Mailcode_Commands_Command_If_Empty)
51
        {
52
            return $this->translateEmpty($command);
53
        }
54
        
55
        if($command instanceof Mailcode_Commands_Command_If_NotEmpty)
56
        {
57
            return $this->translateNotEmpty($command);
58
        }
59
        
60
        return '';
61
    }
62
    
63
    protected function translateCommand(Mailcode_Commands_Command_If_Command $command) : string
64
    {
65
        return $this->_translateGeneric($command);
66
    }
67
    
68
    protected function translateVariable(Mailcode_Commands_Command_If_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_If_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_If_Empty $command) : string
87
    {
88
        return $this->_translateEmpty($command->getVariable(), false);
89
    }
90
    
91
    protected function translateNotEmpty(Mailcode_Commands_Command_If_NotEmpty $command) : string
92
    {
93
        return $this->_translateEmpty($command->getVariable(), true);
94
    }
95
}
96