Completed
Push — master ( 8786b6...8e35b4 )
by Michael
8s
created

onuninstall.php ➔ xoops_module_pre_uninstall_randomquote()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 3
eloc 12
c 1
b 1
f 1
nc 3
nop 1
dl 0
loc 21
rs 9.3142
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits of
4
 supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit
6
 authors.
7
8
 This program is distributed in the hope that it will be useful, but
9
 WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * Module: RandomQuote
14
 *
15
 * @category        Module
16
 * @package         randomquote
17
 * @author          XOOPS Module Development Team
18
 * @author          ZySpec <[email protected]>
19
 * @copyright       {@link http://xoops.org 2001-2016 XOOPS Project}
20
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
21
 * @link            http://xoops.org XOOPS
22
 * @since           2.00
23
 */
24
25
/**
26
 *
27
 * Prepares system prior to attempting to uninstall module
28
 * @param obj $module {@link XoopsModule}
29
 *
30
 * @return bool true if ready to uninstall, false if not
31
 */
32
function xoops_module_pre_uninstall_randomquote(&$module)
0 ignored issues
show
Coding Style introduced by
xoops_module_pre_uninstall_randomquote 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...
33
{
34
    // Do some synchronization with tags to remove tags associated with this module
35
36
    $success = true;
37
    $tagModule = XoopsModule::getByDirname('tag');
38
    if ($tagModule instanceof XoopsModule) {
0 ignored issues
show
Bug introduced by
The class XoopsModule does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
39
        // first delete all quotes
40
        $quotesHandler = xoops_getmodulehandler('quotes', $module->dirname());
41
        $quoteObjs     = $quotesHandler->deleteAll();
0 ignored issues
show
Unused Code introduced by
$quoteObjs 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...
42
        //now 'unlink' the quote tags from Tag modules
43
        include_once $GLOBALS['xoops']->path("/modules/tag/include/functions.recon.php");
44
        $success = tag_synchronization();
45
        if (!$success) {
46
            xoops_loadLanguage('admin', $module->dirname());
47
            $module->setErrors(_AM_RANDOMQUOTE_ERROR_TAG_REMOVAL);
48
        }
49
    }
50
51
    return $success;
52
}
53
54
/**
55
 *
56
 * Performs tasks required during uninstallation of the module
57
 * @param obj $module {@link XoopsModule}
58
 *
59
 * @return bool true if uninstallation successful, false if not
60
 */
61
function xoops_module_uninstall_randomquote(&$module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

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

Loading history...
62
{
63
    $success = true;
64
    return $success;
65
}
66