Completed
Push — master ( 2ebe1b...b0c184 )
by Michael
01:49
created

oninstall.php ➔ xoops_module_install_contact()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 59
Code Lines 24

Duplication

Lines 13
Ratio 22.03 %

Importance

Changes 0
Metric Value
cc 6
eloc 24
nc 8
nop 1
dl 13
loc 59
rs 8.7117
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
 * 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
//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...
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_contact(\XoopsModule $module)
30
{
31
    $moduleDirName = basename(dirname(__DIR__));
32
    /** @var ContactUtility $utility */
33
    $utility    = ucfirst($moduleDirName) . 'Utility';
34
    if (!class_exists($utility)) {
35
        xoops_load('utility', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_load 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

35
        /** @scrutinizer ignore-call */ 
36
        xoops_load('utility', $moduleDirName);
Loading history...
36
    }
37
38
    $xoopsSuccess = $utility::checkVerXoops($module);
39
    $phpSuccess   = $utility::checkVerPhp($module);
40
41
    if (false !== $xoopsSuccess && false !==  $phpSuccess) {
42
        $mod_tables =& $module->getInfo('tables');
43
        foreach ($mod_tables as $table) {
44
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
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_contact(\XoopsModule $module)
58
{
59
    require_once  __DIR__ . '/../../../mainfile.php';
60
    require_once  __DIR__ . '/../include/config.php';
61
62
    $moduleDirName = basename(dirname(__DIR__));
63
64
    $helper       = Contact\Helper::getInstance();
0 ignored issues
show
Bug introduced by
The type Contact\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
65
    $utility      = new Contact\Utility();
0 ignored issues
show
Bug introduced by
The type Contact\Utility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
66
    $configurator = new Contact\Configurator();
0 ignored issues
show
Bug introduced by
The type Contact\Configurator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
    // Load language files
68
    $helper->loadLanguage('admin');
69
    $helper->loadLanguage('modinfo');
70
71
    // default Permission Settings ----------------------
72
//    global $xoopsModule;
73
    $moduleId     = $module->getVar('mid');
74
//    $moduleId2    = $helper->getModule()->mid();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
75
    /** @var \XoopsGroupPermHandler $grouppermHandler */
76
    $grouppermHandler = 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

76
    $grouppermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
77
    // access rights ------------------------------------------
78
    $grouppermHandler->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...
79
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
80
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
81
    $grouppermHandler->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...
82
    $grouppermHandler->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...
83
84
    //  ---  CREATE FOLDERS ---------------
85
    if (count($configurator->uploadFolders) > 0) {
86
        //    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...
87
        foreach (array_keys($configurator->uploadFolders) as $i) {
88
            $utility::createFolder($configurator->uploadFolders[$i]);
89
        }
90
    }
91
92
    //  ---  COPY blank.png FILES ---------------
93
    if (count($configurator->copyBlankFiles) > 0) {
94
        $file = __DIR__ . '/../assets/images/blank.png';
95
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
96
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
97
            $utility::copyFile($file, $dest);
98
        }
99
    }
100
    //delete .html entries from the tpl table
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
101
//    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
102
//    $GLOBALS['xoopsDB']->queryF($sql);
103
104
    return true;
105
}
106