Passed
Push — master ( 6ab608...f87868 )
by Sebastian
03:03
created

Mailcode_Renderer::showSnippet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Renderer} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Utilities
7
 * @see Mailcode_Renderer
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Used to easily create commands and convert them to strings,
16
 * either in plain text or highlighted.
17
 *
18
 * @package Mailcode
19
 * @subpackage Utilities
20
 * @author Sebastian Mordziol <[email protected]>
21
 */
22
class Mailcode_Renderer
23
{
24
   /**
25
    * @var boolean
26
    */
27
    protected $highlighted = false;
28
    
29
   /**
30
    * Sets whether to output highlighted commands instead of the default plain text.
31
    * 
32
    * @param bool $highlighted
33
    * @return Mailcode_Renderer
34
    */
35
    public function setOutputHighlighted(bool $highlighted=true) : Mailcode_Renderer
36
    {
37
        $this->highlighted = $highlighted;
38
        
39
        return $this;
40
    }
41
    
42
   /**
43
    * Converts a show variable command to string.
44
    * 
45
    * @param string $variableName The variable name, with or without $ sign.
46
    * @return string
47
    */
48
    public function showVar(string $variableName) : string
49
    {
50
        return $this->command2string(Mailcode_Factory::showVar($variableName));
51
    }
52
53
    public function showSnippet(string $snippetName) : string
54
    {
55
        return $this->command2string(Mailcode_Factory::showSnippet($snippetName));
56
    }
57
    
58
    public function setVar(string $variableName, string $value, bool $quoteValue=false) : string
59
    {
60
        return $this->command2string(Mailcode_Factory::setVar($variableName, $value, $quoteValue));
61
    }
62
    
63
    public function setVarString(string $variableName, string $value) : string
64
    {
65
        return $this->command2string(Mailcode_Factory::setVarString($variableName, $value));
66
    }
67
    
68
    public function if(string $condition, string $type='') : string
69
    {
70
        return $this->command2string(Mailcode_Factory::if($condition, $type));
71
    }
72
    
73
    public function ifVar(string $variable, string $operand, string $value, bool $quoteValue=false) : string
74
    {
75
        return $this->command2string(Mailcode_Factory::ifVar($variable, $operand, $value, $quoteValue));
76
    }
77
78
    public function ifVarString(string $variable, string $operand, string $value) : string
79
    {
80
        return $this->command2string(Mailcode_Factory::ifVarString($variable, $operand, $value));
81
    }
82
    
83
    public function ifVarEquals(string $variable, string $value, bool $quoteValue=false) : string
84
    {
85
        return $this->command2string(Mailcode_Factory::ifVarEquals($variable, $value, $quoteValue));
86
    }
87
88
    public function ifVarEqualsString(string $variable, string $value) : string
89
    {
90
        return $this->command2string(Mailcode_Factory::ifVarEqualsString($variable, $value));    
91
    }
92
    
93
    public function ifVarNotEquals(string $variable, string $value, bool $quoteValue=false) : string
94
    {
95
        return $this->command2string(Mailcode_Factory::ifVarNotEquals($variable, $value, $quoteValue));
96
    }
97
98
    public function ifVarNotEqualsString(string $variable, string $value) : string
99
    {
100
        return $this->command2string(Mailcode_Factory::ifVarNotEqualsString($variable, $value));
101
    }
102
    
103
    public function elseIf(string $condition, string $type='') : string
104
    {
105
        return $this->command2string(Mailcode_Factory::elseIf($condition, $type));
106
    }
107
    
108
    public function elseIfVar(string $variable, string $operand, string $value, bool $quoteValue=false) : string
109
    {
110
        return $this->command2string(Mailcode_Factory::elseIfVar($variable, $operand, $value, $quoteValue));
111
    }
112
113
    public function elseIfVarString(string $variable, string $operand, string $value) : string
114
    {
115
        return $this->command2string(Mailcode_Factory::elseIfVarString($variable, $operand, $value));
116
    }
117
    
118
    public function elseIfVarEquals(string $variable, string $value, bool $quoteValue=false) : string
119
    {
120
        return $this->command2string(Mailcode_Factory::elseIfVarEquals($variable, $value, $quoteValue));
121
    }
122
123
    public function elseIfVarEqualsString(string $variable, string $value) : string
124
    {
125
        return $this->command2string(Mailcode_Factory::elseIfVarEqualsString($variable, $value));
126
    }
127
    
128
    public function elseIfVarNotEquals(string $variable, string $value, bool $quoteValue=false) : string
129
    {
130
        return $this->command2string(Mailcode_Factory::elseIfVarNotEquals($variable, $value, $quoteValue));
131
    }
132
133
    public function elseIfVarNotEqualsString(string $variable, string $value) : string
134
    {
135
        return $this->command2string(Mailcode_Factory::elseIfVarNotEqualsString($variable, $value));
136
    }
137
    
138
    public function else() : string
139
    {
140
        return $this->command2string(Mailcode_Factory::else());
141
    }
142
    
143
    public function end() : string
144
    {
145
        return $this->command2string(Mailcode_Factory::end());
146
    }
147
    
148
    public function comment(string $comment) : string
149
    {
150
        return $this->command2string(Mailcode_Factory::comment($comment));
151
    }
152
    
153
    protected function command2string(Mailcode_Commands_Command $command) : string
154
    {
155
        if($this->highlighted)
156
        {
157
            return $command->getHighlighted();
158
        }
159
        
160
        return $command->getNormalized();
161
    }
162
}
163