Passed
Push — master ( 005d4f...8b5e26 )
by Michael
06:49
created

xoops_module_install_pedigree()   B

Complexity

Conditions 9
Paths 16

Size

Total Lines 70
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 31
c 1
b 0
f 0
nc 16
nop 1
dl 0
loc 70
rs 8.0555

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 36 and the first side effect is on line 28.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 * animal module for xoops
13
 *
14
 * @package         XoopsModules\Pedigree
15
 * @copyright       The TXMod XOOPS Project https://sourceforge.net/projects/thmod/
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GPL 2.0 or later
18
 * @author          XOOPS Development Team <https://xoops.org>
19
 */
20
21
use Xmf\Module\Helper\Permission;
22
use XoopsModules\Pedigree\{
23
    Common\Configurator,
24
    Constants,
25
    Helper,
26
    Utility
27
};
28
require 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_pedigree(\XoopsModule $module)
37
{
38
    //check for minimum XOOPS version
39
    $xoopsSuccess = Utility::checkVerXoops($module);
40
41
    // check for minimum PHP version
42
    $phpSuccess = Utility::checkVerPhp($module);
43
44
    // delete the SQL tables if they exist, check to make sure they were deleted (DROPPED)
45
    /** @TODO: use Xmf\Tables to handle dropping tables from dB */
46
    $sqlSuccess = true;
47
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
48
        $moduleTables = $module->getInfo('tables');
49
        foreach ($moduleTables as $table) {
50
            $success = $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
51
            $success = false === $success || true;
52
            $sqlSuccess = $sqlSuccess && $success;
53
        }
54
    }
55
56
    return $xoopsSuccess && $phpSuccess && $sqlSuccess;
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
 */
65
function xoops_module_install_pedigree(\XoopsModule $module)
66
{
67
    $helper        = Helper::getInstance();
68
    $moduleDirName = $helper->getDirname();
69
    $configurator  = new Configurator();
70
71
    // Load language files
72
    $helper->loadLanguage('admin');
73
    $helper->loadLanguage('modinfo');
74
75
    // default Permission Settings ----------------------
76
    $mid = $module->getVar('mid');
0 ignored issues
show
Unused Code introduced by
The assignment to $mid is dead and can be removed.
Loading history...
77
78
    // access rights ------------------------------------------
79
    $permHandler = new Permission($moduleDirName);
80
    $permHandler->savePermissionForItem($moduleDirName . '_approve', 1, [XOOPS_GROUP_ADMIN]);
81
    $permHandler->savePermissionForItem($moduleDirName . '_submit', 1, [XOOPS_GROUP_ADMIN]);
82
    $permHandler->savePermissionForItem($moduleDirName . '_view', 1, [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS]);
83
84
    //$moduleName = $module->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...
85
    /** @var \XoopsGroupPermHandler $grouppermHandler */
86
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
87
        $grouppermHandler = xoops_getHandler('groupperm');
88
        // access rights ------------------------------------------
89
        $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
90
        $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
91
        $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
92
        $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
93
        $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
94
    */
95
    //  ---  CREATE FOLDERS ---------------
96
    if (count($configurator->uploadFolders) > 0) {
97
        //    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...
98
        foreach (array_keys($configurator->uploadFolders) as $i) {
99
            Utility::createFolder($configurator->uploadFolders[$i]);
100
        }
101
    }
102
    //  ---  COPY blank.png FILES ---------------
103
    if (count($configurator->copyBlankFiles) > 0) {
104
        $file = $helper->path('assets/images/blank.png');
105
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
106
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
107
            Utility::copyFile($file, $dest);
108
        }
109
    }
110
111
    //  ---  COPY blank.png FILES ---------------
112
    if (count($configurator->copyBlankFiles) > 0) {
113
        $file = dirname(__DIR__) . '/assets/images/blank.png';
114
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
115
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
116
            Utility::copyFile($file, $dest);
117
        }
118
    }
119
120
    //  ---  COPY test folder files ---------------
121
    if (count($configurator->copyTestFolders) > 0) {
122
        //$file =  dirname(__DIR__) . '/testdata/images/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
123
        foreach (array_keys($configurator->copyTestFolders) as $i) {
124
            $src  = $configurator->copyTestFolders[$i][0];
125
            $dest = $configurator->copyTestFolders[$i][1];
126
            Utility::rcopy($src, $dest);
127
        }
128
    }
129
130
    //delete .html entries from the tpl table
131
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $moduleDirName . "' AND `tpl_file` LIKE '%.html'";
132
    $GLOBALS['xoopsDB']->queryF($sql);
133
134
    return true;
135
}
136