Passed
Branch feature/php-docs2 (9f8cc0)
by Michael
04:49
created

Helper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getInstance() 0 8 2
A getHandler() 0 15 2
A getDirname() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Protector;
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.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 * @author      XOOPS Development Team
19
 */
20
21
use XoopsModules\Protector;
22
23
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
24
25
/**
26
 * Class Helper
27
 */
28
class Helper extends \Xmf\Module\Helper
29
{
30
    public $debug;
31
32
    /**
33
     * @param bool $debug
34
     */
35
    public function __construct($debug = false)
36
    {
37
        $this->debug = $debug;
38
        $moduleDirName = \basename(\dirname(__DIR__));
39
        parent::__construct($moduleDirName);
40
    }
41
42
    /**
43
     * @param bool $debug
44
     *
45
     * @return  Protector\Helper
46
     */
47
    public static function getInstance($debug = false)
48
    {
49
        static $instance;
50
        if (null === $instance) {
51
            $instance = new static($debug);
52
        }
53
54
        return $instance;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getDirname()
61
    {
62
        return $this->dirname;
63
    }
64
65
    /**
66
     * Get an Object Handler
67
     *
68
     * @param string $name name of handler to load
69
     *
70
     * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler
71
     */
72
    public function getHandler($name)
73
    {
74
        $ret = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
75
76
        $class = __NAMESPACE__ . '\\' . ucfirst($name) . 'Handler';
77
        if (!class_exists($class)) {
78
            throw new \RuntimeException("Class '$class' not found");
79
        }
80
        /** @var \XoopsMySQLDatabase $db */
81
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
82
        $helper = self::getInstance();
83
        $ret = new $class($db, $helper);
84
        $this->addLog("Getting handler '{$name}'");
85
86
        return $ret;
87
    }
88
}
89