Passed
Push — master ( 37a2f2...290aa0 )
by Michael
02:35
created

xoops_module_install_xfguestbook()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 56
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 29
nc 8
nop 1
dl 0
loc 56
rs 8.2114
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
 * 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 https://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 XoopsModules\Xfguestbook;
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_xfguestbook(\XoopsModule $module)
30
{
31
    include __DIR__ . '/common.php';
32
    /** @var \XoopsModules\Xfguestbook\Utility $utility */
33
    $utility = new \XoopsModules\Xfguestbook\Utility();
34
    //check for minimum XOOPS version
35
    $xoopsSuccess = $utility::checkVerXoops($module);
36
37
    // check for minimum PHP version
38
    $phpSuccess   = $utility::checkVerPhp($module);
39
40
    if (false !== $xoopsSuccess && false !==  $phpSuccess) {
41
        $moduleTables =& $module->getInfo('tables');
42
        foreach ($moduleTables as $table) {
43
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
44
        }
45
    }
46
47
    return $xoopsSuccess && $phpSuccess;
48
}
49
50
/**
51
 *
52
 * Performs tasks required during installation of the module
53
 * @param XoopsModule $module {@link XoopsModule}
54
 *
55
 * @return bool true if installation successful, false if not
56
 */
57
function xoops_module_install_xfguestbook(\XoopsModule $module)
58
{
59
    require_once dirname(__DIR__) . '/preloads/autoloader.php';
60
61
    $moduleDirName = basename(dirname(__DIR__));
62
    /** @var \XoopsModules\Xfguestbook\Helper $helper */
63
    $helper = \XoopsModules\Xfguestbook\Helper::getInstance();
64
65
    // Load language files
66
    $helper->loadLanguage('admin');
67
    $helper->loadLanguage('modinfo');
68
69
    /** @var Xfguestbook\Common\Configurator $configurator */
70
    $configurator = new Xfguestbook\Common\Configurator();
71
    /** @var \XoopsModules\Xfguestbook\Utility $utility */
72
    $utility = new \XoopsModules\Xfguestbook\Utility();
73
74
    // default Permission Settings ----------------------
75
    global $xoopsModule;
76
    $moduleId     = $module->getVar('mid');
77
//    $moduleId2    = $helper->getModule()->mid();
78
    $grouppermHandler = xoops_getHandler('groupperm');
79
    // access rights ------------------------------------------
80
    $grouppermHandler->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

80
    $grouppermHandler->/** @scrutinizer ignore-call */ 
81
                       addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
Loading history...
81
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
82
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
83
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
84
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
85
86
    //  ---  CREATE FOLDERS ---------------
87
    if (count($configurator->uploadFolders) > 0) {
88
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
89
        foreach (array_keys($configurator->uploadFolders) as $i) {
90
            $utility::createFolder($configurator->uploadFolders[$i]);
91
        }
92
    }
93
94
    //  ---  COPY blank.png FILES ---------------
95
    if (count($configurator->copyBlankFiles) > 0) {
96
        $file =  dirname(__DIR__) . '/assets/images/blank.png';
97
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
98
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
99
            $utility::copyFile($file, $dest);
100
        }
101
    }
102
103
    //  ---  COPY test msg image ---------------
104
    if (is_array ($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) {
105
        foreach (array_keys($configurator->copyTestFolders) as $i) {
106
            $src  = $configurator->copyTestFolders[$i][0];
107
            $dest = $configurator->copyTestFolders[$i][1];
108
            $utility::rcopy($src, $dest);
109
        }
110
    }
111
112
    return true;
113
}
114