Completed
Push — master ( 8d9a9b...cd572c )
by Richard
11s
created

XoopsFormRenderer::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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 XOOPS Project (http://xoops.org)
18
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
19
 * @link      http://xoops.org
20
 */
21
class XoopsFormRenderer
22
{
23
    /**
24
     * @var XoopsFormRenderer The reference to *Singleton* instance of this class
25
     */
26
    private static $instance;
27
28
    /**
29
     * @var XoopsFormRendererInterface The reference to *Singleton* instance of this class
30
     */
31
    protected $renderer;
32
33
    /**
34
     * Returns the *Singleton* instance of this class.
35
     *
36
     * @return XoopsFormRenderer the singleton instance.
37
     */
38
    public static function getInstance()
39
    {
40
        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; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
41
            static::$instance = new static();
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
42
        }
43
44
        return 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; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
45
    }
46
47
    /**
48
     * Protected constructor to prevent creating a new instance of the
49
     * *Singleton* via the `new` operator from outside of this class.
50
     */
51
    protected function __construct()
52
    {
53
    }
54
55
    /**
56
     * Private clone method to prevent cloning of the instance of the
57
     * *Singleton* instance.
58
     *
59
     * @return void
60
     */
61
    private function __clone()
62
    {
63
    }
64
65
    /**
66
     * Private unserialize method to prevent unserializing of the *Singleton*
67
     * instance.
68
     *
69
     * @return void
70
     */
71
    private function __wakeup()
72
    {
73
    }
74
75
    /**
76
     * set the renderer
77
     *
78
     * @param XoopsFormRendererInterface $renderer instance of renderer
79
     *
80
     * @return void
81
     */
82
    public function set(XoopsFormRendererInterface $renderer)
83
    {
84
        $this->renderer = $renderer;
85
    }
86
87
    /**
88
     * set the renderer
89
     *
90
     * @param XoopsFormRendererInterface $renderer instance of renderer
0 ignored issues
show
Bug introduced by
There is no parameter named $renderer. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
91
     *
92
     * @return void
0 ignored issues
show
Documentation introduced by
Should the return type not be XoopsFormRendererInterface?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
93
     */
94
    public function get()
95
    {
96
        // return a default if not set
97
        if (null === $this->renderer) {
98
            xoops_load('xoopsformrendererlegacy');
99
            $this->renderer = new XoopsFormRendererLegacy();
100
        }
101
102
        return $this->renderer;
103
    }
104
}
105