Passed
Push — master ( 1bc300...987c24 )
by Michael
01:47
created

xoops_module_install_moduleinstaller()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 47
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 28
nc 4
nop 1
dl 0
loc 47
rs 8.5125
c 2
b 0
f 0
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\Moduleinstaller;
21
//require_once __DIR__ . '/setup.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
22
23
/**
24
 *
25
 * Prepares system prior to attempting to install module
26
 * @param XoopsModule $module {@link XoopsModule}
27
 *
28
 * @return bool true if ready to install, false if not
29
 */
30
function xoops_module_pre_install_moduleinstaller(\XoopsModule $module)
31
{
32
    include __DIR__ . '/../preloads/autoloader.php';
33
    /** @var Moduleinstaller\Utility $utility */
34
    $utility = new \XoopsModules\Moduleinstaller\Utility();
35
    $xoopsSuccess = $utility::checkVerXoops($module);
36
    $phpSuccess   = $utility::checkVerPhp($module);
37
38
    if (false !== $xoopsSuccess && false !==  $phpSuccess) {
39
        $moduleTables =& $module->getInfo('tables');
40
        foreach ($moduleTables as $table) {
41
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
42
        }
43
    }
44
45
    return $xoopsSuccess && $phpSuccess;
46
}
47
48
/**
49
 *
50
 * Performs tasks required during installation of the module
51
 * @param XoopsModule $module {@link XoopsModule}
52
 *
53
 * @return bool true if installation successful, false if not
54
 */
55
function xoops_module_install_moduleinstaller(\XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed. ( Ignorable by Annotation )

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

55
function xoops_module_install_moduleinstaller(/** @scrutinizer ignore-unused */ \XoopsModule $module)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
{
57
    require_once  __DIR__ . '/../../../mainfile.php';
58
    require_once  __DIR__ . '/../include/config.php';
59
60
    $moduleDirName = basename(dirname(__DIR__));
61
62
    $helper       = Moduleinstaller\Helper::getInstance();
63
    $utility      = new Moduleinstaller\Utility();
0 ignored issues
show
Unused Code introduced by
The assignment to $utility is dead and can be removed.
Loading history...
64
    $configurator = new Moduleinstaller\Common\Configurator();
65
    // Load language files
66
    $helper->loadLanguage('admin');
67
    $helper->loadLanguage('modinfo');
68
69
    // default Permission Settings ----------------------
70
    global $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
71
    $moduleId     = $xoopsModule->getVar('mid');
72
    $moduleId2    = $helper->getModule()->mid();
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleId2 is dead and can be removed.
Loading history...
73
    $gpermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

73
    $gpermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
74
    // access rights ------------------------------------------
75
    $gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_ADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
76
    $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
77
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
78
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_USERS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
79
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
80
81
    //  ---  CREATE FOLDERS ---------------
82
    if (count($configurator->uploadFolders) > 0) {
83
        //    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...
84
        foreach (array_keys($configurator->uploadFolders) as $i) {
85
            $utilityClass::createFolder($configurator->uploadFolders[$i]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $utilityClass does not exist. Did you maybe mean $utility?
Loading history...
86
        }
87
    }
88
89
    //  ---  COPY blank.png FILES ---------------
90
    if (count($configurator->copyBlankFiles) > 0) {
91
        $file = __DIR__ . '/../assets/images/blank.png';
92
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
93
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
94
            $utilityClass::copyFile($file, $dest);
95
        }
96
    }
97
    //delete .html entries from the tpl table
98
    $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsDB seems to be never defined.
Loading history...
99
    $xoopsDB->queryF($sql);
100
101
    return true;
102
}
103