Helper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 68
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 9 2
A getHandler() 0 21 2
A __construct() 0 7 1
A getDirname() 0 3 1
1
<?php
2
3
namespace XoopsModules\Chess;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    XOOPS Project https://xoops.org/
17
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
18
 * @package      Chess
19
 * @since        2.01
20
 * @author       XOOPS Development Team
21
 */
22
//defined('XOOPS_ROOT_PATH') || die('Restricted access');
23
24
/**
25
 * Class Helper
26
 */
27
class Helper extends \Xmf\Module\Helper
28
{
29
    public $debug;
30
31
    /**
32
     * @param bool $debug
33
     */
34
    public function __construct($debug = false)
35
    {
36
        $this->debug = $debug;
37
38
        $moduleDirName = \basename(\dirname(__DIR__));
39
40
        parent::__construct($moduleDirName);
41
    }
42
43
    /**
44
     * @param bool $debug
45
     *
46
     * @return \XoopsModules\Chess\Helper
47
     */
48
    public static function getInstance($debug = false)
49
    {
50
        static $instance;
51
52
        if (null === $instance) {
53
            $instance = new static($debug);
54
        }
55
56
        return $instance;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getDirname()
63
    {
64
        return $this->dirname;
65
    }
66
67
    /**
68
     * Get an Object Handler
69
     *
70
     * @param string $name name of handler to load
71
     *
72
     * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler
73
     */
74
    public function getHandler($name)
75
    {
76
        $ret = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
77
78
        $class = __NAMESPACE__ . '\\' . $name . 'Handler';
79
80
        if (!\class_exists($class)) {
81
            throw new \RuntimeException("Class '$class' not found");
82
        }
83
84
        /** @var \XoopsMySQLDatabase $db */
85
86
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
87
88
        $helper = self::getInstance();
89
90
        $ret = new $class($db, $helper);
91
92
        $this->addLog("Getting handler '{$name}'");
93
94
        return $ret;
95
    }
96
}
97
//require  dirname(dirname(__DIR__)) . '/mainfile.php';
98