XoopsFormRenderer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __wakeup() 0 3 1
A set() 0 3 1
A getInstance() 0 7 2
A __construct() 0 2 1
A get() 0 9 2
A __clone() 0 3 1
1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 * This program is distributed in the hope that it will be useful,
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
 */
10
11
/**
12
 * Factory to build handlers
13
 *
14
 * @category  XoopsForm
15
 * @package   XoopsFormRenderer
16
 * @author    Richard Griffith <[email protected]>
17
 * @copyright 2017-2020 XOOPS Project (https://xoops.org)
18
 * @license   GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @link      https://xoops.org
20
 */
21
final class XoopsFormRenderer
22
{
23
    const NOT_PERMITTED = 'Not supported for Singleton';
24
25
    /**
26
     * @var XoopsFormRenderer The reference to *Singleton* instance of this class
27
     */
28
    private static $instance;
29
30
    /**
31
     * @var XoopsFormRendererInterface The reference to *Singleton* instance of this class
32
     */
33
    protected $renderer;
34
35
    /**
36
     * Returns the *Singleton* instance of this class.
37
     *
38
     * @return XoopsFormRenderer the singleton instance.
39
     */
40
    public static function getInstance()
41
    {
42
        if (null === static::$instance) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $instance to at least protected.
Loading history...
43
            static::$instance = new static();
44
        }
45
46
        return static::$instance;
47
    }
48
49
    /**
50
     * Protected constructor to prevent creating a new instance of the
51
     * *Singleton* via the `new` operator from outside of this class.
52
     */
53
    protected function __construct()
54
    {
55
    }
56
57
    /**
58
     * Private clone method to prevent cloning of the instance of the
59
     * *Singleton* instance.
60
     *
61
     * @return void
62
     *
63
     * @throws \LogicException
64
     */
65
    public function __clone()
66
    {
67
        throw new \LogicException(static::NOT_PERMITTED);
68
    }
69
70
    /**
71
     * Private unserialize method to prevent unserializing of the *Singleton*
72
     * instance.
73
     *
74
     * @return void
75
     *
76
     * @throws \LogicException
77
     */
78
    public function __wakeup()
79
    {
80
        throw new \LogicException(static::NOT_PERMITTED);
81
    }
82
83
    /**
84
     * set the renderer
85
     *
86
     * @param XoopsFormRendererInterface $renderer instance of renderer
87
     *
88
     * @return void
89
     */
90
    public function set(XoopsFormRendererInterface $renderer)
91
    {
92
        $this->renderer = $renderer;
93
    }
94
95
    /**
96
     * get the renderer
97
     *
98
     * @return XoopsFormRendererInterface
99
     */
100
    public function get()
101
    {
102
        // return a default if not set
103
        if (null === $this->renderer) {
104
            xoops_load('xoopsformrendererlegacy');
105
            $this->renderer = new XoopsFormRendererLegacy();
106
        }
107
108
        return $this->renderer;
109
    }
110
}
111