Passed
Pull Request — master (#17)
by
unknown
04:15
created

Mailcode_Factory_CommandSets_Set_Show::dateNow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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