Passed
Pull Request — master (#13)
by
unknown
03:37
created

Mailcode_Factory_CommandSets_Set::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 {@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
39
    public function end(): Mailcode_Commands_Command_End
40
    {
41
        $cmd = $this->commands->createCommand(
42
            'End',
43
            '',
44
            '',
45
            '{end}'
46
        );
47
48
        $this->instantiator->checkCommand($cmd);
49
50
        if ($cmd instanceof Mailcode_Commands_Command_End) {
51
            return $cmd;
52
        }
53
54
        throw $this->instantiator->exceptionUnexpectedType('End', $cmd);
55
    }
56
57
    protected function quoteString(string $string): string
58
    {
59
        if (substr($string, 0, 1) === '"' && substr($string, -1, 1) === '"') {
60
            return $string;
61
        }
62
63
        return '"' . str_replace('"', '\"', $string) . '"';
64
    }
65
}
66