Completed
Push — master ( fe4c2e...b05117 )
by Michael
12s
created

Helper::getHelper()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 22
rs 8.9197
ccs 0
cts 10
cp 0
cc 4
eloc 11
nc 4
nop 1
crap 20
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
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
namespace Xmf\Module;
13
14
use Xmf\Module\Helper\GenericHelper;
15
16
/**
17
 * Helper gets an instance of module helper for the specified module.
18
 * The helper is defined by the Xoops 2.6 Xoops\Module\Helper\HelperAbstract
19
 * and in pre 2.6 systems we mimic that definition with using an
20
 * instance of Xmf\Module\GenericHelper.
21
 *
22
 * @category  Xmf\Module\Helper
23
 * @package   Xmf
24
 * @author    trabis <[email protected]>
25
 * @author    Richard Griffith <[email protected]>
26
 * @copyright 2011-2016 XOOPS Project (http://xoops.org)
27
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
28
 * @version   Release: 1.0
29
 * @link      http://xoops.org
30
 * @since     1.0
31
 */
32
class Helper extends GenericHelper
33
{
34
    /**
35
     * Get an instance of a module helper for the module identified by $dirname
36
     *
37
     * @param string $dirname module directory
38
     *
39
     * @return \Xmf\Module\Helper|\Xoops\Module\Helper|false a Helper object of false on error
40
     */
41
    public static function getHelper($dirname = 'system')
42
    {
43
        static $instance = array();
44
45
        $dirname = strtolower($dirname);
46
47
        if (!isset($instance[$dirname])) {
48
            $instance[$dirname] = false;
49
50
            // if this is a 2.6 system turn everything over to the core
51
            if (class_exists('Xoops', false)) {
52
                $instance[$dirname] = \Xoops\Module\Helper::getHelper($dirname);
53
            } else {
54
                // otherwise get a GenericHelper instance for dirname
55
                if (xoops_isActiveModule($dirname)) {
0 ignored issues
show
Deprecated Code introduced by
The function xoops_isActiveModule() has been deprecated.

This function has been deprecated.

Loading history...
56
                    $instance[$dirname] = new static($dirname);
57
                }
58
            }
59
        }
60
61
        return $instance[$dirname];
62
    }
63
}
64