Passed
Push — master ( 0c35c3...4c9016 )
by Sebastian
03:25 queued 12s
created

Mailcode_Factory_CommandSets_Set_Set::setVar()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 26
rs 9.8333
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory_CommandSets_Set_Set} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Utilities
7
 * @see Mailcode_Factory_CommandSets_Set_Set
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_Set extends Mailcode_Factory_CommandSets_Set
22
{
23
    public function var(string $variableName, string $value, bool $quoteValue=true) : Mailcode_Commands_Command_SetVariable
24
    {
25
        $variableName = $this->instantiator->filterVariableName($variableName);
26
        
27
        if($quoteValue)
28
        {
29
            $value = $this->instantiator->quoteString($value);
30
        }
31
        
32
        $params = $variableName.' = '.$value;
33
        
34
        $cmd = Mailcode::create()->getCommands()->createCommand(
35
            'SetVariable',
36
            '', // type
37
            $params,
38
            '{setvar: '.$params.'}'
39
        );
40
        
41
        $this->instantiator->checkCommand($cmd);
42
        
43
        if($cmd instanceof Mailcode_Commands_Command_SetVariable)
44
        {
45
            return $cmd;
46
        }
47
        
48
        throw $this->instantiator->exceptionUnexpectedType('SetVariable', $cmd);
49
    }
50
51
    /**
52
     * Treats the value as a string literal, so automatically adds quotes around it.
53
     *
54
     * @param string $variableName
55
     * @param string $value
56
     * @return Mailcode_Commands_Command_SetVariable
57
     * @throws Mailcode_Factory_Exception
58
     */
59
    public function varString(string $variableName, string $value) : Mailcode_Commands_Command_SetVariable
60
    {
61
        return $this->var($variableName, $value, true);
62
    }
63
}
64