Passed
Push — master ( 75ee28...758f58 )
by Sebastian
04:00
created

showNumber()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 32
rs 9.6666
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory_CommandSets_Set_Show} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Utilities
7
 * @see Mailcode_Factory_CommandSets_Set_Show
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Command set used to create showxxx commands.
16
 *
17
 * @package Mailcode
18
 * @subpackage Utilities
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Factory_CommandSets_Set_Show extends Mailcode_Factory_CommandSets_Set
22
{
23
    public function showVar(string $variableName) : Mailcode_Commands_Command_ShowVariable
24
    {
25
        $variableName = $this->instantiator->filterVariableName($variableName);
26
        
27
        $cmd = Mailcode::create()->getCommands()->createCommand(
28
            'ShowVariable',
29
            '',
30
            $variableName,
31
            '{showvar:'.$variableName.'}'
32
        );
33
        
34
        $this->instantiator->checkCommand($cmd);
35
        
36
        if($cmd instanceof Mailcode_Commands_Command_ShowVariable)
37
        {
38
            return $cmd;
39
        }
40
        
41
        throw $this->instantiator->exceptionUnexpectedType('ShowVariable', $cmd);
42
    }
43
    
44
    public function showDate(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowDate
45
    {
46
        $variableName = $this->instantiator->filterVariableName($variableName);
47
        
48
        $format = '';
49
        if(!empty($formatString))
50
        {
51
            $format = sprintf(
52
                ' "%s"',
53
                $formatString
54
            );
55
        }
56
        
57
        $cmd = Mailcode::create()->getCommands()->createCommand(
58
            'ShowDate',
59
            '',
60
            $variableName.$format,
61
            sprintf(
62
                '{showdate: %s%s}',
63
                $variableName,
64
                $format
65
            )
66
        );
67
        
68
        $this->instantiator->checkCommand($cmd);
69
        
70
        if($cmd instanceof Mailcode_Commands_Command_ShowDate)
71
        {
72
            return $cmd;
73
        }
74
        
75
        throw $this->instantiator->exceptionUnexpectedType('ShowDate', $cmd);
76
    }
77
78
    public function showNumber(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowNumber
79
    {
80
        $variableName = $this->instantiator->filterVariableName($variableName);
81
82
        $format = '';
83
        if(!empty($formatString))
84
        {
85
            $format = sprintf(
86
                ' "%s"',
87
                $formatString
88
            );
89
        }
90
91
        $cmd = Mailcode::create()->getCommands()->createCommand(
92
            'ShowNumber',
93
            '',
94
            $variableName.$format,
95
            sprintf(
96
                '{shownumber: %s%s}',
97
                $variableName,
98
                $format
99
            )
100
        );
101
102
        $this->instantiator->checkCommand($cmd);
103
104
        if($cmd instanceof Mailcode_Commands_Command_ShowNumber)
105
        {
106
            return $cmd;
107
        }
108
109
        throw $this->instantiator->exceptionUnexpectedType('ShowNumber', $cmd);
110
    }
111
    
112
    public function showSnippet(string $snippetName) : Mailcode_Commands_Command_ShowSnippet
113
    {
114
        $snippetName = $this->instantiator->filterVariableName($snippetName);
115
        
116
        $cmd = Mailcode::create()->getCommands()->createCommand(
117
            'ShowSnippet',
118
            '',
119
            $snippetName,
120
            '{showsnippet:'.$snippetName.'}'
121
        );
122
        
123
        $this->instantiator->checkCommand($cmd);
124
        
125
        if($cmd instanceof Mailcode_Commands_Command_ShowSnippet)
126
        {
127
            return $cmd;
128
        }
129
        
130
        throw $this->instantiator->exceptionUnexpectedType('ShowSnippet', $cmd);
131
    }
132
}
133