Completed
Branch master (c921ab)
by Michael
109:50 queued 98:29
created

oninstall.php ➔ xoops_module_pre_install_extcal()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 24
rs 8.5125
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 http://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team
16
 */
17
18
/**
19
 *
20
 * Prepares system prior to attempting to install module
21
 * @param XoopsModule $module {@link XoopsModule}
22
 *
23
 * @return bool true if ready to install, false if not
24
 */
25
function xoops_module_pre_install_extcal(XoopsModule $module)
0 ignored issues
show
Coding Style introduced by
xoops_module_pre_install_extcal uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
26
{
27
    $moduleDirName = basename(dirname(__DIR__));
28
    $className     = ucfirst($moduleDirName) . 'Utilities';
29
    if (!class_exists($className)) {
30
        xoops_load('utilities', $moduleDirName);
31
    }
32
    //check for minimum XOOPS version
33
    if (!$className::checkXoopsVer($module)) {
34
        return false;
35
    }
36
37
    // check for minimum PHP version
38
    if (!$className::checkPhpVer($module)) {
39
        return false;
40
    }
41
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 true;
48
}
49
50
/**
51
 *
52
 * Performs tasks required during installation of the module
53
 * @param XoopsModule $xoopsModule
54
 * @return bool true if installation successful, false if not
55
 * @internal param XoopsModule $module <a href='psi_element://XoopsModule'>XoopsModule</a>
56
 *
57
 */
58
function xoops_module_install_extcal(XoopsModule $xoopsModule)
0 ignored issues
show
Best Practice introduced by
The function xoops_module_install_extcal() has been defined more than once; this definition is ignored, only the first definition in include/install_function.php (L8-43) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Coding Style introduced by
xoops_module_install_extcal uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
59
{
60
    $moduleDirName = basename(dirname(__DIR__));
61
62
    $moduleId = $xoopsModule->getVar('mid');
63
    /** @var XoopsGroupPermHandler $groupPermissionHandler */
64
    $groupPermissionHandler = xoops_getHandler('groupperm');
65
    /** @var XoopsConfigHandler $configHandler */
66
    $configHandler = xoops_getHandler('config');
67
68
    /*
69
     * Default public category permission mask
70
     */
71
72
    // Access right
73
    $groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_ADMIN, $moduleId);
74
    $groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_USERS, $moduleId);
75
    $groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
76
77
    // Can submit
78
    $groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 2, XOOPS_GROUP_ADMIN, $moduleId);
79
80
    // Auto approve
81
    $groupPermissionHandler->addRight($moduleDirName . '_perm_mask', 4, XOOPS_GROUP_ADMIN, $moduleId);
82
83
    //    $moduleDirName = $xoopsModule->getVar('dirname');
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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
    $configurator = include $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/config.php');
85
86
    $classUtilities = ucfirst($moduleDirName) . 'Utilities';
87
    if (!class_exists($classUtilities)) {
88
        xoops_load('utilities', $moduleDirName);
89
    }
90
91
    if (count($configurator['uploadFolders']) > 0) {
92
        //    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...
93
        foreach (array_keys($configurator['uploadFolders']) as $i) {
94
            $classUtilities::createFolder($configurator['uploadFolders'][$i]);
95
        }
96
    }
97 View Code Duplication
    if (count($configurator['copyFiles']) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
        $file = __DIR__ . '/../assets/images/blank.png';
99
        foreach (array_keys($configurator['copyFiles']) as $i) {
100
            $dest = $configurator['copyFiles'][$i] . '/blank.png';
101
            $classUtilities::copyFile($file, $dest);
102
        }
103
    }
104
105
    return true;
106
}
107