Passed
Pull Request — master (#11)
by Michael
01:53
created

Helper::getDirname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Xsitemap;
4
5
/**
6
 * Class Helper
7
 */
8
class Helper extends \Xmf\Module\Helper
9
{
10
    public $debug;
11
12
    /**
13
     * @param bool $debug
14
     */
15
    public function __construct($debug = false)
16
    {
17
        $this->debug   = $debug;
18
        $moduleDirName = \basename(\dirname(__DIR__));
19
        parent::__construct($moduleDirName);
20
    }
21
22
    /**
23
     * @param bool $debug
24
     *
25
     * @return \XoopsModules\Xsitemap\Helper
26
     */
27
    public static function getInstance($debug = false)
28
    {
29
        static $instance;
30
        if (null === $instance) {
31
            $instance = new static($debug);
32
        }
33
        return $instance;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getDirname()
40
    {
41
        return $this->dirname;
42
    }
43
44
    /**
45
     * Get an Object Handler
46
     *
47
     * @param string $name name of handler to load
48
     *
49
     * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler
50
     */
51
    public function getHandler($name)
52
    {
53
        $ret   = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
54
        $class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler';
55
        if (!\class_exists($class)) {
56
            throw new \RuntimeException("Class '$class' not found");
57
        }
58
        /** @var \XoopsMySQLDatabase $db */
59
        $db     = \XoopsDatabaseFactory::getDatabaseConnection();
60
        $helper = self::getInstance();
61
        $ret    = new $class($db, $helper);
62
        $this->addLog("Getting handler '{$name}'");
63
        return $ret;
64
    }
65
}
66