Test Setup Failed
Push — master ( e4f8c2...f9e497 )
by Sebastian
03:34
created

Mailcode_Factory_CommandSets_Set_Misc::break()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory_CommandSets_Set_Misc} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Utilities
7
 * @see Mailcode_Factory_CommandSets_Set_Misc
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Factory utility used to create commands.
16
 *
17
 * @package Mailcode
18
 * @subpackage Utilities
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Factory_CommandSets_Set_Misc extends Mailcode_Factory_CommandSets_Set
22
{
23
    public function comment(string $comments) : Mailcode_Commands_Command_Comment
24
    {
25
        $cmd = Mailcode::create()->getCommands()->createCommand(
26
            'Comment',
27
            '', // type
28
            $comments, // params
29
            sprintf(
30
                '{comment: %s}',
31
                $comments
32
            )
33
        );
34
    
35
        $this->instantiator->checkCommand($cmd);
36
        
37
        if($cmd instanceof Mailcode_Commands_Command_Comment)
38
        {
39
            return $cmd;
40
        }
41
        
42
        throw $this->instantiator->exceptionUnexpectedType('Comment', $cmd);
43
    }
44
    
45
    public function for(string $sourceVariable, string $loopVariable) : Mailcode_Commands_Command_For
46
    {
47
        $sourceVariable = '$'.ltrim($sourceVariable, '$');
48
        $loopVariable = '$'.ltrim($loopVariable, '$');
49
        
50
        $cmd = Mailcode::create()->getCommands()->createCommand(
51
            'For', 
52
            '', 
53
            sprintf(
54
                '%s in: %s',
55
                $loopVariable,
56
                $sourceVariable
57
            ), 
58
            sprintf(
59
                '{for: %s in: %s}',
60
                $loopVariable,
61
                $sourceVariable
62
            )
63
        );
64
        
65
        $this->instantiator->checkCommand($cmd);
66
        
67
        if($cmd instanceof Mailcode_Commands_Command_For)
68
        {
69
            return $cmd;
70
        }
71
        
72
        throw $this->instantiator->exceptionUnexpectedType('For', $cmd);
73
    }
74
75
    public function break() : Mailcode_Commands_Command_Break
76
    {
77
        $cmd = Mailcode::create()->getCommands()->createCommand(
78
            'Break',
79
            '',
80
            '',
81
            '{break}'
82
        );
83
84
        $this->instantiator->checkCommand($cmd);
85
86
        if($cmd instanceof Mailcode_Commands_Command_Break)
87
        {
88
            return $cmd;
89
        }
90
91
        throw $this->instantiator->exceptionUnexpectedType('Break', $cmd);
92
    }
93
94
    public function code(string $language) : Mailcode_Commands_Command_Code
95
    {
96
        $cmd = Mailcode::create()->getCommands()->createCommand(
97
            'Code',
98
            '',
99
            sprintf(
100
                '"%s"',
101
                $language
102
            ),
103
            sprintf(
104
                '{code: "%s"}',
105
                $language
106
            )
107
        );
108
109
        $this->instantiator->checkCommand($cmd);
110
111
        if($cmd instanceof Mailcode_Commands_Command_Code)
112
        {
113
            return $cmd;
114
        }
115
116
        throw $this->instantiator->exceptionUnexpectedType('Code', $cmd);
117
    }
118
}
119