Passed
Pull Request — master (#18)
by Sebastian
07:37
created

Mailcode_Factory_CommandSets_Set_Show::date()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 4
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 = false,
65
                          string $currencyString = null, string $currencyVariable = null,
66
                          string $regionString = null, string $regionVariable = null): Mailcode_Commands_Command_ShowPrice
67
    {
68
        return (new Price())->create($variableName, $absolute, $withCurrencyName, $currencyString, $currencyVariable, $regionString, $regionVariable);
69
    }
70
71
    /**
72
     * Creates a `showphone` command.
73
     *
74
     * @param string $variableName The name of the variable, with or without $ sign.
75
     * @param string $sourceFormat Two-letter country code, case-insensitive.
76
     * @param string $urlEncoding The URL encoding mode, if any.
77
     * @return Mailcode_Commands_Command_ShowPhone
78
     * @throws Mailcode_Factory_Exception
79
     */
80
    public function phone(string $variableName, string $sourceFormat, string $urlEncoding = Mailcode_Factory::URL_ENCODING_NONE): Mailcode_Commands_Command_ShowPhone
81
    {
82
        return (new Phone())->create($variableName, $sourceFormat, $urlEncoding);
83
    }
84
85
    /**
86
     * @param string $snippetName The name of the snippet to show.
87
     * @return Mailcode_Commands_Command_ShowSnippet
88
     * @throws Mailcode_Factory_Exception
89
     */
90
    public function snippet(string $snippetName): Mailcode_Commands_Command_ShowSnippet
91
    {
92
        return (new Snippet())->create($snippetName);
93
    }
94
95
    /**
96
     * @param string $url The target URL. Can contain Mailcode.
97
     * @param string|null $trackingID If not set, an auto-generated tracking ID will be used.
98
     * @param array<string,string> $queryParams
99
     * @return Mailcode_Commands_Command_ShowURL
100
     * @throws Mailcode_Factory_Exception
101
     */
102
    public function url(string $url, ?string $trackingID = null, array $queryParams = array()): Mailcode_Commands_Command_ShowURL
103
    {
104
        return (new URL())->create($url, $trackingID, $queryParams);
105
    }
106
107
    /**
108
     * @param string $subject The string to encode
109
     * @param string[] $encodings The encodings (keywords) to enable
110
     * @return Mailcode_Commands_Command_ShowEncoded
111
     * @throws Mailcode_Factory_Exception
112
     */
113
    public function encoded(string $subject, array $encodings): Mailcode_Commands_Command_ShowEncoded
114
    {
115
        return (new Encoded())->create($subject, $encodings);
116
    }
117
}
118