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

Date   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 32 3
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