Passed
Push — master ( 77f2a3...0c35c3 )
by Sebastian
03:02
created

translateNotContains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 translateCommand(Mailcode_Commands_Command_If_Command $command) : string
34
    {
35
        return $this->_translateGeneric($command);
36
    }
37
    
38
    protected function translateBeginsWith(Mailcode_Commands_Command_If_BeginsWith $command) : string
39
    {
40
        return $this->_translateSearch(
41
            'starts',
42
            $command->getVariable(),
43
            $command->isCaseInsensitive(),
44
            $command->getSearchTerm()
45
        );
46
    }
47
    
48
    protected function translateEndsWith(Mailcode_Commands_Command_If_EndsWith $command) : string
49
    {
50
        return $this->_translateSearch(
51
            'ends',
52
            $command->getVariable(),
53
            $command->isCaseInsensitive(),
54
            $command->getSearchTerm()
55
        );
56
    }
57
58
    protected function translateBiggerThan(Mailcode_Commands_Command_If_BiggerThan $command) : string
59
    {
60
        return $this->_translateNumberComparison(
61
            $command->getVariable(),
62
            $command->getNumber(),
63
            '>'
64
        );
65
    }
66
67
    protected function translateSmallerThan(Mailcode_Commands_Command_If_SmallerThan $command) : string
68
    {
69
        return $this->_translateNumberComparison(
70
            $command->getVariable(),
71
            $command->getNumber(),
72
            '<'
73
        );
74
    }
75
76
    protected function translateEqualsNumber(Mailcode_Commands_Command_If_EqualsNumber $command) : string
77
    {
78
        return $this->_translateNumberComparison(
79
            $command->getVariable(),
80
            $command->getNumber(),
81
            '=='
82
        );
83
    }
84
85
    protected function translateVariable(Mailcode_Commands_Command_If_Variable $command) : string
86
    {
87
        return $this->_translateVariable(
88
            $command->getVariable(), 
89
            $command->getSign(), 
90
            $command->getValue()
91
        );
92
    }
93
    
94
    protected function translateContains(Mailcode_Commands_Command_If_Contains $command) : string
95
    {
96
        return $this->_translateContains(
97
            $command->getVariable(), 
98
            $command->isCaseInsensitive(), 
99
            $command->getSearchTerms(),
100
            $command->getType()
101
        );
102
    }
103
104
    protected function translateNotContains(Mailcode_Commands_Command_If_NotContains $command) : string
105
    {
106
        return $this->_translateContains(
107
            $command->getVariable(),
108
            $command->isCaseInsensitive(),
109
            $command->getSearchTerms(),
110
            $command->getType()
111
        );
112
    }
113
    
114
    protected function translateEmpty(Mailcode_Commands_Command_If_Empty $command) : string
115
    {
116
        return $this->_translateEmpty($command->getVariable(), false);
117
    }
118
    
119
    protected function translateNotEmpty(Mailcode_Commands_Command_If_NotEmpty $command) : string
120
    {
121
        return $this->_translateEmpty($command->getVariable(), true);
122
    }
123
}
124