xoops_module_install_cardealer()   B
last analyzed

Complexity

Conditions 7
Paths 8

Size

Total Lines 58
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 30
nc 8
nop 1
dl 0
loc 58
rs 8.5066
c 1
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: cardealer
15
 *
16
 * @category        Module
17
 * @package         cardealer
18
 * @author          XOOPS Development Team <[email protected]> - <https://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 XoopsModules\Cardealer;
26
use XoopsModules\Cardealer\Common;
27
28
include dirname(__DIR__) . '/preloads/autoloader.php';
29
30
/**
31
 * Prepares system prior to attempting to install module
32
 * @param \XoopsModule $module {@link XoopsModule}
33
 *
34
 * @return bool true if ready to install, false if not
35
 */
36
function xoops_module_pre_install_cardealer(\XoopsModule $module)
37
{
38
    /** @var Cardealer\Utility $utility */
39
    $utility = new Cardealer\Utility();
40
41
    //check for minimum XOOPS version
42
    $xoopsSuccess = $utility::checkVerXoops($module);
43
44
    // check for minimum PHP version
45
    $phpSuccess = $utility::checkVerPhp($module);
46
47
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
48
        $moduleTables =& $module->getInfo('tables');
49
        foreach ($moduleTables as $table) {
50
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
51
        }
52
    }
53
    return $xoopsSuccess && $phpSuccess;
54
}
55
56
/**
57
 *
58
 * Performs tasks required during installation of the module
59
 * @param XoopsModule $module {@link XoopsModule}
60
 *
61
 * @return bool true if installation successful, false if not
62
 */
63
function xoops_module_install_cardealer(\XoopsModule $module)
64
{
65
    $moduleDirName = basename(dirname(__DIR__));
66
67
    /** @var Cardealer\Helper $helper */
68
    /** @var Cardealer\Utility $utility */
69
    /** @var Common\Configurator $configurator */
70
    $helper       = Cardealer\Helper::getInstance();
71
    $utility      = new Cardealer\Utility();
72
    $configurator = new Common\Configurator();
73
74
    // Load language files
75
    $helper->loadLanguage('admin');
76
    $helper->loadLanguage('modinfo');
77
78
    // default Permission Settings ----------------------
79
    $moduleId  = $module->getVar('mid');
80
    $moduleId2 = $helper->getModule()->mid();
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleId2 is dead and can be removed.
Loading history...
81
    //$moduleName = $module->getVar('name');
82
    $gpermHandler = xoops_getHandler('groupperm');
83
    // access rights ------------------------------------------
84
    $gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
The method addRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
    $gpermHandler->/** @scrutinizer ignore-call */ 
85
                   addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
Loading history...
85
    $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
86
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
87
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
88
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
89
90
    //  ---  CREATE FOLDERS ---------------
91
    if (count($configurator->uploadFolders) > 0) {
92
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
93
        foreach (array_keys($configurator->uploadFolders) as $i) {
94
            $utility::createFolder($configurator->uploadFolders[$i]);
95
        }
96
    }
97
    //  ---  COPY blank.png FILES ---------------
98
    if (count($configurator->copyBlankFiles) > 0) {
99
        $file = __DIR__ . '/../assets/images/blank.png';
100
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
101
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
102
            $utility::copyFile($file, $dest);
103
        }
104
    }
105
106
    //  ---  COPY test folder files ---------------
107
    if (count($configurator->copyTestFolders) > 0) {
108
        //        $file = __DIR__ . '/../testdata/images/';
109
        foreach (array_keys($configurator->copyTestFolders) as $i) {
110
            $src  = $configurator->copyTestFolders[$i][0];
111
            $dest = $configurator->copyTestFolders[$i][1];
112
            $utility::xcopy($src, $dest);
113
        }
114
    }
115
116
    //delete .html entries from the tpl table
117
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
118
    $GLOBALS['xoopsDB']->queryF($sql);
119
120
    return true;
121
}
122