Completed
Push — master ( a1059e...55b12e )
by Michael
01:29
created

oninstall.php ➔ xoops_module_install_marquee()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 49
Code Lines 29

Duplication

Lines 13
Ratio 26.53 %

Importance

Changes 0
Metric Value
cc 5
eloc 29
nc 4
nop 1
dl 13
loc 49
rs 8.5906
c 0
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
use \XoopsModules\Marquee;
13
14
/**
15
 * @copyright    XOOPS Project https://xoops.org/
16
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package
18
 * @since
19
 * @author       XOOPS Development Team
20
 */
21
22
//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...
23
24
/**
25
 *
26
 * Prepares system prior to attempting to install module
27
 * @param \XoopsModule $module {@link XoopsModule}
28
 *
29
 * @return bool true if ready to install, false if not
30
 */
31
function xoops_module_pre_install_marquee(\XoopsModule $module)
0 ignored issues
show
Coding Style introduced by
xoops_module_pre_install_marquee 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...
32
{
33
34
    include __DIR__ . '/../preloads/autoloader.php';
35
    /** @var \Utility $utility */
36
    $utility = new \Marquee\Utility();
37
    $xoopsSuccess = $utility::checkVerXoops($module);
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_marquee(\XoopsModule $module)
0 ignored issues
show
Coding Style introduced by
xoops_module_install_marquee 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...
58
{
59
    require_once  __DIR__ . '/../../../mainfile.php';
60
    require_once  __DIR__ . '/../include/config.php';
61
62
    $moduleDirName = basename(dirname(__DIR__));
63
64
    $helper       = Marquee\Helper::getInstance();
65
    $utility      = new Marquee\Utility();
66
    $configurator = new Marquee\Configurator();
67
    // Load language files
68
    $helper->loadLanguage('admin');
69
    $helper->loadLanguage('modinfo');
70
71
72
    // default Permission Settings ----------------------
73
    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...
74
    $moduleId     = $xoopsModule->getVar('mid');
75
    $moduleId2    = $helper->getModule()->mid();
0 ignored issues
show
Unused Code introduced by
$moduleId2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76
    $gpermHandler = xoops_getHandler('groupperm');
77
    // access rights ------------------------------------------
78
    $gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
79
    $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
80
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
81
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
82
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
83
84
    //  ---  CREATE FOLDERS ---------------
85 View Code Duplication
    if (count($configurator->uploadFolders) > 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...
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 View Code Duplication
    if (count($configurator->blankFiles) > 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...
94
        $file = __DIR__ . '/../assets/images/blank.png';
95
        foreach (array_keys($configurator->blankFiles) as $i) {
96
            $dest = $configurator->blankFiles[$i] . '/blank.png';
97
            $utility::copyFile($file, $dest);
98
        }
99
    }
100
    //delete .html entries from the tpl table
101
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
102
    $xoopsDB->queryF($sql);
0 ignored issues
show
Bug introduced by
The variable $xoopsDB does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
103
104
    return true;
105
}
106
107