Test Failed
Push — master ( 9ff364...742ef2 )
by Sebastian
03:58
created

Date::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 18
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 32
rs 9.6666
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\Mailcode_Commands_Command_ShowDate;
15
use Mailcode\Mailcode_Factory_CommandSets_Set;
16
17
/**
18
 * Factory class for the `showdate` command.
19
 *
20
 * @package Mailcode
21
 * @subpackage Factory
22
 * @author Sebastian Mordziol <[email protected]>
23
 */
24
class Date extends Mailcode_Factory_CommandSets_Set
25
{
26
    public function create(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowDate
27
    {
28
        $variableName = $this->instantiator->filterVariableName($variableName);
29
30
        $format = '';
31
        if(!empty($formatString))
32
        {
33
            $format = sprintf(
34
                ' "%s"',
35
                $formatString
36
            );
37
        }
38
39
        $cmd = $this->commands->createCommand(
40
            'ShowDate',
41
            '',
42
            $variableName.$format,
43
            sprintf(
44
                '{showdate: %s%s}',
45
                $variableName,
46
                $format
47
            )
48
        );
49
50
        $this->instantiator->checkCommand($cmd);
51
52
        if($cmd instanceof Mailcode_Commands_Command_ShowDate)
53
        {
54
            return $cmd;
55
        }
56
57
        throw $this->instantiator->exceptionUnexpectedType('ShowDate', $cmd);
58
    }
59
}
60