Completed
Push — master ( 0a3d23...5fac45 )
by Michael
02:58
created

functions.config.php ➔ newbbLoadConfig()   C

Complexity

Conditions 7
Paths 17

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 15
nc 17
nop 0
dl 0
loc 24
rs 6.7272
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * NewBB 5.0x,  the forum module for XOOPS project
4
 *
5
 * @copyright      XOOPS Project (https://xoops.org)
6
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
7
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
8
 * @since          4.00
9
 * @package        module::newbb
10
 */
11
12
// 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...
13
14
defined('NEWBB_FUNCTIONS_INI') || include_once __DIR__ . '/functions.ini.php';
15
define('NEWBB_FUNCTIONS_CONFIG_LOADED', true);
16
17
if (!defined('NEWBB_FUNCTIONS_CONFIG')) {
18
    define('NEWBB_FUNCTIONS_CONFIG', 1);
19
20
    /**
21
     * @return array
22
     * @internal param string $category
23
     * @internal param string $dirname
24
     */
25
    function newbbLoadConfig()
0 ignored issues
show
Coding Style introduced by
newbbLoadConfig 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...
26
    {
27
        include_once dirname(__DIR__) . '/class/helper.php';
28
        $helper = NewBB::getInstance();
29
        static $configs = null;
30
31
        if (null !== $configs) {
32
            return $configs;
33
        }
34
35
        $configs = is_object($helper) ? $helper->getConfig() : [];
36
        $plugins = include __DIR__ . '/plugin.php';
37
        if (is_array($configs) && is_array($plugins)) {
38
            $configs = array_merge($configs, $plugins);
39
        }
40
        if (!isset($GLOBALS['xoopsModuleConfig'])) {
41
            $GLOBALS['xoopsModuleConfig'] = [];
42
        }
43
        if (is_array($configs)) {
44
            $GLOBALS['xoopsModuleConfig']= array_merge( $GLOBALS['xoopsModuleConfig'], $configs);
45
        }
46
47
        return $configs;
48
    }
49
}
50