xoops_module_install_countdown()   B
last analyzed

Complexity

Conditions 8
Paths 16

Size

Total Lines 62
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 31
nc 16
nop 1
dl 0
loc 62
rs 8.1795
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
declare(strict_types=1);
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * Module: Countdown
17
 *
18
 * @category        Module
19
 * @package         Countdown
20
 * @author          XOOPS Development Team <[email protected]> - <https://xoops.org>
21
 * @copyright       {@link https://xoops.org/ XOOPS Project}
22
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 * @link            https://xoops.org/
24
 * @since           1.0.0
25
 */
26
27
use XoopsModules\Countdown;
28
use XoopsModules\Countdown\Common;
29
30
require dirname(__DIR__) . '/preloads/autoloader.php';
31
32
/**
33
 * Prepares system prior to attempting to install module
34
 * @param \XoopsModule $module {@link XoopsModule}
35
 *
36
 * @return bool true if ready to install, false if not
37
 */
38
function xoops_module_pre_install_countdown(\XoopsModule $module)
39
{
40
    /** @var Countdown\Utility $utility */
41
    $utility = new Countdown\Utility();
42
43
    //check for minimum XOOPS version
44
    $xoopsSuccess = $utility::checkVerXoops($module);
45
46
    // check for minimum PHP version
47
    $phpSuccess = $utility::checkVerPhp($module);
48
49
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
50
        $moduleTables =& $module->getInfo('tables');
51
        foreach ($moduleTables as $table) {
52
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
53
        }
54
    }
55
    return $xoopsSuccess && $phpSuccess;
56
}
57
58
/**
59
 *
60
 * Performs tasks required during installation of the module
61
 * @param XoopsModule $module {@link XoopsModule}
62
 *
63
 * @return bool true if installation successful, false if not
64
 * @throws \UnexpectedValueException
65
 */
66
function xoops_module_install_countdown(\XoopsModule $module)
67
{
68
    $moduleDirName = basename(dirname(__DIR__));
69
70
    /** @var Countdown\Helper $helper */ /** @var Countdown\Utility $utility */
71
    /** @var Common\Configurator $configurator */
72
    $helper       = Countdown\Helper::getInstance();
73
    $utility      = new Countdown\Utility();
74
    $configurator = new Common\Configurator();
75
76
    // Load language files
77
    $helper->loadLanguage('admin');
78
    $helper->loadLanguage('modinfo');
79
80
    // default Permission Settings ----------------------
81
    //    $moduleId0  = $module->getVar('mid');
82
    $moduleId = $helper->getModule()->mid();
83
    //$moduleName = $module->getVar('name');
84
    /** @var \XoopsGroupPermHandler $gpermHandler */
85
    $gpermHandler = xoops_getHandler('groupperm');
86
    // access rights ------------------------------------------
87
    $gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
XOOPS_GROUP_ADMIN of type string is incompatible with the type integer expected by parameter $gperm_groupid of XoopsGroupPermHandler::addRight(). ( Ignorable by Annotation )

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

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