Completed
Push — master ( 31307f...55a138 )
by Michael
03:27
created

Config::getModuleConfig()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 6
nop 0
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
1
<?php namespace XoopsModules\Extcal;
2
3
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4
5
/**
6
 * Class Config.
7
 */
8
class Config
9
{
10
    /**
11
     * @return Config
12
     */
13
    public static function getHandler()
14
    {
15
        static $configHandler;
16
        if (!isset($configHandler[0])) {
17
            $configHandler[0] = new self();
18
        }
19
20
        return $configHandler[0];
21
    }
22
23
    /**
24
     * @return mixed
25
     */
26
    public function getModuleConfig()
0 ignored issues
show
Coding Style introduced by
getModuleConfig uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
27
    {
28
        global $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
        static $moduleConfig;
30
        $dirname = (isset($xoopsModule) ? $xoopsModule->getVar('dirname') : 'system');
31
        if ('extcal' === $dirname) {
32
            $moduleConfig = $GLOBALS['xoopsModuleConfig'];
33
        } else {
34
            if (!isset($moduleConfig)) {
35
                /** @var XoopsModuleHandler $moduleHandler */
36
                $moduleHandler = xoops_getHandler('module');
37
                $module        = $moduleHandler->getByDirname('extcal');
38
                $configHandler = xoops_getHandler('config');
39
                $moduleConfig  = $configHandler->getConfigList($module->getVar('mid'));
40
            }
41
        }
42
43
        return $moduleConfig;
44
    }
45
}
46