Test Failed
Push — master ( 36c5b6...af11e6 )
by Sebastian
04:51
created

Mailcode_Factory::getSets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Utilities
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 Utilities
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Factory
22
{
23
    public const ERROR_INVALID_COMMAND_CREATED = 50001;
24
    public const ERROR_UNEXPECTED_COMMAND_TYPE = 50002;
25
26
    public const URL_ENCODING_NONE = 'none';
27
    public const URL_ENCODING_ENCODE = 'encode';
28
    public const URL_ENCODING_DECODE = 'decode';
29
30
    /**
31
    * @var Mailcode_Factory_CommandSets|NULL
32
    */
33
    private static ?Mailcode_Factory_CommandSets $commandSets = null;
34
35
    /**
36
     * Returns the command set for `show` commands.
37
     *
38
     * @return Mailcode_Factory_CommandSets_Set_Show
39
     */
40
    public static function show() : Mailcode_Factory_CommandSets_Set_Show
41
    {
42
        return self::getSets()->show();
43
    }
44
45
    /**
46
     * Return the command set for `set` commands.
47
     *
48
     * @return Mailcode_Factory_CommandSets_Set_Set
49
     */
50
    public static function set() : Mailcode_Factory_CommandSets_Set_Set
51
    {
52
        return self::getSets()->set();
53
    }
54
55
    /**
56
     * Return the command set for `if` commands.
57
     *
58
     * @return Mailcode_Factory_CommandSets_Set_If
59
     */
60
    public static function if() : Mailcode_Factory_CommandSets_Set_If
61
    {
62
        return self::getSets()->if();
63
    }
64
65
    /**
66
     * Return the command set for `else if` commands.
67
     *
68
     * @return Mailcode_Factory_CommandSets_Set_ElseIf
69
     */
70
    public static function elseIf() : Mailcode_Factory_CommandSets_Set_ElseIf
71
    {
72
        return self::getSets()->elseIf();
73
    }
74
75
    /**
76
     * Return the command set for `miscellaneous` commands.
77
     *
78
     * @return Mailcode_Factory_CommandSets_Set_Misc
79
     */
80
    public static function misc() : Mailcode_Factory_CommandSets_Set_Misc
81
    {
82
        return self::getSets()->misc();
83
    }
84
85
    /**
86
    * Creates a renderer instance, which can be used to easily
87
    * create and convert commands to strings.
88
    * 
89
    * @return Mailcode_Renderer
90
    */
91
    public static function createRenderer() : Mailcode_Renderer
92
    {
93
        return new Mailcode_Renderer();
94
    }
95
    
96
   /**
97
    * Creates a printer instance, which works like the renderer,
98
    * but outputs the generated strings to standard output.
99
    * 
100
    * @return Mailcode_Printer
101
    */
102
    public static function createPrinter() : Mailcode_Printer
103
    {
104
        return new Mailcode_Printer();
105
    }
106
    
107
   /**
108
    * Gets/creates the global instance of the date format info
109
    * class, used to handle date formatting aspects.
110
    * 
111
    * @return Mailcode_Date_FormatInfo
112
    */
113
    public static function createDateInfo() : Mailcode_Date_FormatInfo
114
    {
115
        return Mailcode_Date_FormatInfo::getInstance();
116
    }
117
118
    protected static function getSets() : Mailcode_Factory_CommandSets
119
    {
120
        if(!isset(self::$commandSets))
121
        {
122
            self::$commandSets = new Mailcode_Factory_CommandSets();
123
        }
124
125
        return self::$commandSets;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::commandSets could return the type null which is incompatible with the type-hinted return Mailcode\Mailcode_Factory_CommandSets. Consider adding an additional type-check to rule them out.
Loading history...
126
    }
127
}
128