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

Mailcode_Factory_CommandSets_Set::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Factory
7
 * @see Mailcode_Factory
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Factory utility used to create commands.
16
 *
17
 * @package Mailcode
18
 * @subpackage Factory
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
abstract class Mailcode_Factory_CommandSets_Set
22
{
23
    /**
24
     * @var Mailcode_Factory_Instantiator
25
     */
26
    protected Mailcode_Factory_Instantiator $instantiator;
27
28
    /**
29
     * @var Mailcode_Commands
30
     */
31
    protected Mailcode_Commands $commands;
32
33
    public function __construct()
34
    {
35
        $this->instantiator = new Mailcode_Factory_Instantiator();
36
        $this->commands = Mailcode::create()->getCommands();
37
38
        $this->init();
39
    }
40
41
    protected function init() : void
42
    {
43
44
    }
45
46
    public function end(): Mailcode_Commands_Command_End
47
    {
48
        $cmd = $this->commands->createCommand(
49
            'End',
50
            '',
51
            '',
52
            '{end}'
53
        );
54
55
        $this->instantiator->checkCommand($cmd);
56
57
        if ($cmd instanceof Mailcode_Commands_Command_End) {
58
            return $cmd;
59
        }
60
61
        throw $this->instantiator->exceptionUnexpectedType('End', $cmd);
62
    }
63
64
    protected function quoteString(string $string): string
65
    {
66
        if (substr($string, 0, 1) === '"' && substr($string, -1, 1) === '"') {
67
            return $string;
68
        }
69
70
        return '"' . str_replace('"', '\"', $string) . '"';
71
    }
72
}
73