Passed
Pull Request — master (#18)
by
unknown
03:40
created

Mailcode_Factory_CommandSets_Set_Show::encoded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory_CommandSets_Set_Show} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Factory
7
 * @see Mailcode_Factory_CommandSets_Set_Show
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use Mailcode\Factory\CommandSets\Set\Show\Date;
15
use Mailcode\Factory\CommandSets\Set\Show\Encoded;
16
use Mailcode\Factory\CommandSets\Set\Show\Number;
17
use Mailcode\Factory\CommandSets\Set\Show\Phone;
18
use Mailcode\Factory\CommandSets\Set\Show\Price;
19
use Mailcode\Factory\CommandSets\Set\Show\Snippet;
20
use Mailcode\Factory\CommandSets\Set\Show\URL;
21
22
/**
23
 * Command set used to create showxxx commands.
24
 *
25
 * @package Mailcode
26
 * @subpackage Factory
27
 * @author Sebastian Mordziol <[email protected]>
28
 */
29
class Mailcode_Factory_CommandSets_Set_Show extends Mailcode_Factory_CommandSets_Set
30
{
31
    public function var(string $variableName): Mailcode_Commands_Command_ShowVariable
32
    {
33
        $variableName = $this->instantiator->filterVariableName($variableName);
34
35
        $cmd = $this->commands->createCommand(
36
            'ShowVariable',
37
            '',
38
            $variableName,
39
            sprintf(
40
                '{showvar: %s}',
41
                $variableName
42
            )
43
        );
44
45
        $this->instantiator->checkCommand($cmd);
46
47
        if ($cmd instanceof Mailcode_Commands_Command_ShowVariable) {
48
            return $cmd;
49
        }
50
51
        throw $this->instantiator->exceptionUnexpectedType('ShowVariable', $cmd);
52
    }
53
54
    public function date(string $variableName, string $formatString = "", string $timezoneString = null, string $timezoneVariable = null): Mailcode_Commands_Command_ShowDate
55
    {
56
        return (new Date())->create($variableName, $formatString, $timezoneString, $timezoneVariable);
57
    }
58
59
    public function number(string $variableName, string $formatString = "", bool $absolute = false): Mailcode_Commands_Command_ShowNumber
60
    {
61
        return (new Number())->create($variableName, $formatString, $absolute);
62
    }
63
64
    public function price(string $variableName, bool $absolute = false, bool $withCurrencyName = true): Mailcode_Commands_Command_ShowPrice
65
    {
66
        return (new Price())->create($variableName, $absolute, $withCurrencyName);
67
    }
68
69
    /**
70
     * Creates a `showphone` command.
71
     *
72
     * @param string $variableName The name of the variable, with or without $ sign.
73
     * @param string $sourceFormat Two-letter country code, case-insensitive.
74
     * @param string $urlEncoding The URL encoding mode, if any.
75
     * @return Mailcode_Commands_Command_ShowPhone
76
     * @throws Mailcode_Factory_Exception
77
     */
78
    public function phone(string $variableName, string $sourceFormat, string $urlEncoding = Mailcode_Factory::URL_ENCODING_NONE): Mailcode_Commands_Command_ShowPhone
79
    {
80
        return (new Phone())->create($variableName, $sourceFormat, $urlEncoding);
81
    }
82
83
    /**
84
     * @param string $snippetName The name of the snippet to show.
85
     * @return Mailcode_Commands_Command_ShowSnippet
86
     * @throws Mailcode_Factory_Exception
87
     */
88
    public function snippet(string $snippetName): Mailcode_Commands_Command_ShowSnippet
89
    {
90
        return (new Snippet())->create($snippetName);
91
    }
92
93
    /**
94
     * @param string $url The target URL. Can contain Mailcode.
95
     * @param string|null $trackingID If not set, an auto-generated tracking ID will be used.
96
     * @param array<string,string> $queryParams
97
     * @return Mailcode_Commands_Command_ShowURL
98
     * @throws Mailcode_Factory_Exception
99
     */
100
    public function url(string $url, ?string $trackingID = null, array $queryParams = array()): Mailcode_Commands_Command_ShowURL
101
    {
102
        return (new URL())->create($url, $trackingID, $queryParams);
103
    }
104
105
    /**
106
     * @param string $subject The string to encode
107
     * @param string[] $encodings The encodings (keywords) to enable
108
     * @return Mailcode_Commands_Command_ShowEncoded
109
     * @throws Mailcode_Factory_Exception
110
     */
111
    public function encoded(string $subject, array $encodings): Mailcode_Commands_Command_ShowEncoded
112
    {
113
        return (new Encoded())->create($subject, $encodings);
114
    }
115
}
116