Completed
Push — master ( e876a4...a7100c )
by Michael
01:36
created

oninstall.php ➔ xoops_module_install_equipment()   B

Complexity

Conditions 8
Paths 16

Size

Total Lines 54
Code Lines 31

Duplication

Lines 13
Ratio 24.07 %

Importance

Changes 0
Metric Value
cc 8
eloc 31
nc 16
nop 1
dl 13
loc 54
rs 7.4119
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
*/
12
13
/**
14
 * Module: Equipment
15
 *
16
 * @category        Module
17
 * @package         equipment
18
 * @author          XOOPS Development Team <[email protected]> - <http://xoops.org>
19
 * @copyright       {@link https://xoops.org/ XOOPS Project}
20
 * @license         GPL 2.0 or later
21
 * @link            https://xoops.org/
22
 * @since           1.0.0
23
 */
24
25
use Xmf\Language;
26
27
/**
28
 * Prepares system prior to attempting to install module
29
 * @param XoopsModule $module {@link XoopsModule}
30
 *
31
 * @return bool true if ready to install, false if not
32
 */
33
function xoops_module_pre_install_equipment(XoopsModule $module)
34
{
35
    $moduleDirName = basename(dirname(__DIR__));
36
    $className     = ucfirst($moduleDirName) . 'Utility';
37
    if (!class_exists($className)) {
38
        xoops_load('utility', $moduleDirName);
39
    }
40
    //check for minimum XOOPS version
41
    if (!$className::checkVerXoops($module)) {
42
        return false;
43
    }
44
45
    // check for minimum PHP version
46
    if (!$className::checkVerPhp($module)) {
47
        return false;
48
    }
49
    $mod_tables = $module->getInfo('tables');
50
    foreach ($mod_tables as $table) {
51
        $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
52
    }
53
54
    return true;
55
}
56
57
/**
58
 *
59
 * Performs tasks required during installation of the module
60
 * @param XoopsModule $module {@link XoopsModule}
61
 *
62
 * @return bool true if installation successful, false if not
63
 */
64
function xoops_module_install_equipment(XoopsModule $module)
65
{
66
    require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
67
    //    $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...
68
    $moduleDirName = basename(dirname(__DIR__));
69
    xoops_loadLanguage('admin', $moduleDirName);
70
    xoops_loadLanguage('modinfo', $moduleDirName);
71
    $configurator = include __DIR__ . '/config.php';
72
    $classUtility = ucfirst($moduleDirName) . 'Utility';
73
    if (!class_exists($classUtility)) {
74
        xoops_load('utility', $moduleDirName);
75
    }
76
    global $xoopsModule;
77
    // default Permission Settings
78
    $moduleId = $xoopsModule->getVar('mid');
79
    //$moduleName = $xoopsModule->getVar('name');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
80
    //$moduleDirName = $xoopsModule->getVar('dirname');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
81
    //$moduleVersion = $xoopsModule->getVar('version');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
82
    $gpermHandler = xoops_getHandler('groupperm');
83
    // access rights
84
    $gpermHandler->addRight('equipment_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
85
    $gpermHandler->addRight('equipment_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
86
    $gpermHandler->addRight('equipment_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
87
    $gpermHandler->addRight('equipment_view', 1, XOOPS_GROUP_USERS, $moduleId);
88
    $gpermHandler->addRight('equipment_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
89
90
    //  ---  CREATE FOLDERS ---------------
91 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...
92
        //    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...
93
        foreach (array_keys($configurator['uploadFolders']) as $i) {
94
            $classUtility::createFolder($configurator['uploadFolders'][$i]);
95
        }
96
    }
97
    //  ---  COPY blank.png FILES ---------------
98 View Code Duplication
    if (count($configurator['copyBlankFiles']) > 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...
99
        $file = __DIR__ . '/../assets/images/blank.png';
100
        foreach (array_keys($configurator['copyBlankFiles']) as $i) {
101
            $dest = $configurator['copyBlankFiles'][$i] . '/blank.png';
102
            $classUtility::copyFile($file, $dest);
103
        }
104
    }
105
106
    //  ---  COPY test folder files ---------------
107
    if (count($configurator['copyTestFolders']) > 0) {
108
        //        $file = __DIR__ . '/../testdata/images/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
109
        foreach (array_keys($configurator['copyTestFolders']) as $i) {
110
            $src  = $configurator['copyTestFolders'][$i][0];
111
            $dest = $configurator['copyTestFolders'][$i][1];
112
            $classUtility::recurseCopy($src, $dest);
113
        }
114
    }
115
116
    return true;
117
}
118