Completed
Push — master ( 937117...931dfe )
by Michael
05:45 queued 02:42
created

oninstall.php ➔ xoops_module_pre_install_soapbox()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 8
nop 1
dl 0
loc 24
rs 8.5125
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
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
use Xmf\Language;
21
22
/**
23
 *
24
 * Prepares system prior to attempting to install module
25
 * @param XoopsModule $module {@link XoopsModule}
26
 *
27
 * @return bool true if ready to install, false if not
28
 */
29
function xoops_module_pre_install_soapbox(XoopsModule $module)
0 ignored issues
show
Coding Style introduced by
xoops_module_pre_install_soapbox 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...
30
{
31
    $moduleDirName = basename(dirname(__DIR__));
32
    $classUtility  = ucfirst($moduleDirName) . 'Utility';
33
    if (!class_exists($classUtility)) {
34
        xoops_load('utility', $moduleDirName);
35
    }
36
    //check for minimum XOOPS version
37
    if (!$classUtility::checkVerXoops($module)) {
38
        return false;
39
    }
40
41
    // check for minimum PHP version
42
    if (!$classUtility::checkVerPhp($module)) {
43
        return false;
44
    }
45
46
    $mod_tables =& $module->getInfo('tables');
47
    foreach ($mod_tables as $table) {
48
        $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
49
    }
50
51
    return true;
52
}
53
54
/**
55
 *
56
 * Performs tasks required during installation of the module
57
 * @param XoopsModule $module {@link XoopsModule}
58
 *
59
 * @return bool true if installation successful, false if not
60
 */
61
function xoops_module_install_soapbox(XoopsModule $module)
62
{
63
    require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
64
    require_once __DIR__ . '/../include/config.php';
65
66
    if (!isset($moduleDirName)) {
0 ignored issues
show
Bug introduced by
The variable $moduleDirName seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
67
        $moduleDirName = basename(dirname(__DIR__));
68
    }
69
70
    if (false !== ($moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName))) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
71
    } else {
72
        $moduleHelper = Xmf\Module\Helper::getHelper('system');
73
    }
74
75
    // Load language files
76
    $moduleHelper->loadLanguage('admin');
77
    $moduleHelper->loadLanguage('modinfo');
78
79
    $configurator = new ModuleConfigurator();
80
    $classUtility = ucfirst($moduleDirName) . 'Utility';
81
    if (!class_exists($classUtility)) {
82
        xoops_load('utility', $moduleDirName);
83
    }
84
85
    //  ---  CREATE FOLDERS ---------------
86 View Code Duplication
    if (count($configurator->uploadFolders) > 0) {
0 ignored issues
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...
87
        //    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...
88
        foreach (array_keys($configurator->uploadFolders) as $i) {
89
            $classUtility::createFolder($configurator->uploadFolders[$i]);
90
        }
91
    }
92
93
    //  ---  COPY blank.png FILES ---------------
94 View Code Duplication
    if (count($configurator->blankFiles) > 0) {
0 ignored issues
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...
95
        $file = __DIR__ . '/../assets/images/blank.png';
96
        foreach (array_keys($configurator->blankFiles) as $i) {
97
            $dest = $configurator->blankFiles[$i] . '/blank.png';
98
            $classUtility::copyFile($file, $dest);
99
        }
100
    }
101
102
    return true;
103
}
104