Completed
Branch master (71f789)
by Michael
02:35
created

oninstall.php ➔ xoops_module_install_adslight()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 33
Code Lines 18

Duplication

Lines 13
Ratio 39.39 %

Importance

Changes 0
Metric Value
cc 6
eloc 18
nc 8
nop 1
dl 13
loc 33
rs 8.439
c 0
b 0
f 0
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
/**
13
 * @copyright    XOOPS Project http://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author     XOOPS Development Team
16
 */
17
18
19
/**
20
 *
21
 * Prepares system prior to attempting to install module
22
 * @param XoopsModule $module {@link XoopsModule}
23
 *
24
 * @return bool true if ready to install, false if not
25
 */
26
function xoops_module_pre_install_adslight(XoopsModule $module)
1 ignored issue
show
Coding Style introduced by
xoops_module_pre_install_adslight 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
    $moduleDirName = basename(dirname(__DIR__));
29
    $className = ucfirst($moduleDirName) . 'Utilities';
30
    if (!class_exists($className)) {
31
        xoops_load('utilities', $moduleDirName);
32
    }
33
    //check for minimum XOOPS version
34
    if (!$className::checkXoopsVer($module)) {
35
        return false;
36
    }
37
38
    // check for minimum PHP version
39
    if (!$className::checkPhpVer($module)) {
40
        return false;
41
    }
42
43
    $mod_tables =& $module->getInfo('tables');
44
    foreach ($mod_tables as $table) {
45
        $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
46
    }
47
48
    return true;
49
}
50
51
/**
52
 *
53
 * Performs tasks required during installation of the module
54
 * @param XoopsModule $module {@link XoopsModule}
55
 *
56
 * @return bool true if installation successful, false if not
57
 */
58
function xoops_module_install_adslight(XoopsModule $module)
59
{
60
    include_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
61
62
    //    $moduleDirName = $xoopsModule->getVar('dirname');
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
63
    $moduleDirName = basename(dirname(__DIR__));
64
    xoops_loadLanguage('admin', $moduleDirName);
65
    xoops_loadLanguage('modinfo', $moduleDirName);
66
67
    $configurator = include __DIR__ . '/config.php';
68
    $classUtilities = ucfirst($moduleDirName) . 'Utilities';
69
    if (!class_exists($classUtilities)) {
70
        xoops_load('utilities', $moduleDirName);
71
    }
72
73
    //  ---  CREATE FOLDERS ---------------
74 View Code Duplication
    if (count($configurator['uploadFolders']) > 0) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
76
        foreach (array_keys($configurator['uploadFolders']) as $i) {
77
            $classUtilities::createFolder($configurator['uploadFolders'][$i]);
78
        }
79
    }
80
81
    //  ---  COPY blank.png FILES ---------------
82 View Code Duplication
    if (count($configurator['copyBlankFiles']) > 0) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
        $file = __DIR__ . '/../assets/images/blank.png';
84
        foreach (array_keys($configurator['copyBlankFiles']) as $i) {
85
            $dest = $configurator['copyBlankFiles'][$i] . '/blank.png';
86
            $classUtilities::copyFile($file, $dest);
87
        }
88
    }
89
    return true;
90
}
91