Test Failed
Pull Request — master (#13)
by Sebastian
05:15
created

Date::quoteString()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * File containing the class {@see \Mailcode\Factory\CommandSets\Set\Show\Date}.
4
 *
5
 * @package Mailcode
6
 * @subpackage Factory
7
 * @see \Mailcode\Factory\CommandSets\Set\Show\Date
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode\Factory\CommandSets\Set\Show;
13
14
use Mailcode\Interfaces\Commands\Validation\TimezoneInterface;
15
use Mailcode\Mailcode_Commands_Command_ShowDate;
16
use Mailcode\Mailcode_Factory_CommandSets_Set;
17
18
/**
19
 * Factory class for the `showdate` command.
20
 *
21
 * @package Mailcode
22
 * @subpackage Factory
23
 * @author Sebastian Mordziol <[email protected]>
24
 */
25
class Date extends Mailcode_Factory_CommandSets_Set
26
{
27
    public function create(string $variableName, string $formatString = "", string $timezoneString = null, string $timezoneVariable = null): Mailcode_Commands_Command_ShowDate
28
    {
29
        $variableName = $this->instantiator->filterVariableName($variableName);
30
31
        $format = '';
32
        if (!empty($formatString)) {
33
            $format = sprintf(
34
                ' "%s"',
35
                $formatString
36
            );
37
        }
38
39
        $timezone = '';
40
        if (!empty($timezoneString)) {
41
            $timezone = sprintf(
42
                ' '.TimezoneInterface::PARAMETER_NAME.'=%s',
43
                $this->quoteString($timezoneString)
44
            );
45
        } else if (!empty($timezoneVariable)) {
46
            $timezone = sprintf(
47
                ' '.TimezoneInterface::PARAMETER_NAME.'=%s',
48
                $timezoneVariable
49
            );
50
        }
51
52
        $cmd = $this->commands->createCommand(
53
            'ShowDate',
54
            '',
55
            $variableName . $format . $timezone,
56
            sprintf(
57
                '{showdate: %s%s%s}',
58
                $variableName,
59
                $format,
60
                $timezone
61
            )
62
        );
63
64
        $this->instantiator->checkCommand($cmd);
65
66
        if ($cmd instanceof Mailcode_Commands_Command_ShowDate) {
67
            return $cmd;
68
        }
69
70
        throw $this->instantiator->exceptionUnexpectedType('ShowDate', $cmd);
71
    }
72
}
73