Completed
Branch master (55a138)
by Michael
03:21
created

Helper::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php namespace XoopsModules\Extcal;
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 25 and the first side effect is on line 20.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author     XOOPS Development Team
18
 */
19
20
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21
22
/**
23
 * Class Helper
24
 */
25
class Helper extends \Xmf\Module\Helper
26
{
27
    public $debug;
28
29
    /**
30
     * @internal param $debug
31
     * @param bool $debug
32
     */
33
    protected function __construct($debug = false)
34
    {
35
        $this->debug   = $debug;
36
        $this->dirname = basename(dirname(__DIR__));
37
    }
38
39
    /**
40
     * @param bool $debug
41
     *
42
     * @return \Helper
43
     */
44
    public static function getInstance($debug = false)
45
    {
46
        static $instance;
47
        if (null === $instance) {
48
            $instance = new static($debug);
49
        }
50
51
        return $instance;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getDirname()
58
    {
59
        return $this->dirname;
60
    }
61
62
    /**
63
     * Get an Object Handler
64
     *
65
     * @param string $name name of handler to load
66
     *
67
     * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler
0 ignored issues
show
Documentation introduced by
Should the return type not be object?

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...
68
     */
69
    public function getHandler($name)
70
    {
71
        $ret   = false;
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
        $db    = \XoopsDatabaseFactory::getDatabaseConnection();
73
        $class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler';
74
        $ret   = new $class($db);
75
        return $ret;
76
    }
77
}
78
79
80