xoops_module_uninstall_wgevents()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 55
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 55
rs 9.8333

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
/**
4
 * uninstall.php - cleanup on module uninstall
5
 *
6
 * @author          XOOPS Module Development Team
7
 * @copyright       {@link https://xoops.org 2001-2016 XOOPS Project}
8
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
9
 * @link            https://xoops.org XOOPS
10
 */
11
12
use XoopsModules\Wgevents;
13
14
/**
15
 * Prepares system prior to attempting to uninstall module
16
 * @param \XoopsModule $module {@link XoopsModule}
17
 *
18
 * @return bool true if ready to uninstall, false if not
19
 */
20
function xoops_module_pre_uninstall_wgevents(\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

20
function xoops_module_pre_uninstall_wgevents(/** @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...
21
{
22
    // Do some synchronization
23
    return true;
24
}
25
26
/**
27
 * Performs tasks required during uninstallation of the module
28
 * @param \XoopsModule $module {@link XoopsModule}
29
 *
30
 * @return bool true if uninstallation successful, false if not
31
 */
32
function xoops_module_uninstall_wgevents(\XoopsModule $module)
33
{
34
    $moduleDirName      = \basename(\dirname(__DIR__));
35
    $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
36
37
    $helper = Wgevents\Helper::getInstance();
38
    $utility = new Wgevents\Utility();
39
40
    $success = true;
41
    $helper->loadLanguage('admin');
42
43
    //------------------------------------------------------------------
44
    // Remove uploads folder (and all subfolders) if they exist
45
    //------------------------------------------------------------------
46
    $uploads_dir = $GLOBALS['xoops']->path("uploads/$moduleDirName");
47
    $dirInfo = new \SplFileInfo($uploads_dir);
48
    // if directory exists so delete it
49
    if ($dirInfo->isDir() && !$utility::rrmdir($uploads_dir)) {
50
        $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH'), $uploads_dir));
51
        $success = false;
52
    }
53
    unset($dirInfo);
54
55
    //------------------------------------------------------------------
56
    // Rename uploads folder to BAK and add date to name
57
    // NOT USED CURRENTLY
58
    //------------------------------------------------------------------
59
    /*
60
    $uploadDirectory = $GLOBALS['xoops']->path("uploads/$moduleDirName");
61
    $dirInfo = new \SplFileInfo($uploadDirectory);
62
    if ($dirInfo->isDir()) {
63
        // The directory exists so rename it
64
        $date = date('Y-m-d');
65
        if (!\rename($uploadDirectory, $uploadDirectory . "_bak_$date")) {
66
            $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH'), $uploadDirectory));
67
            $success = false;
68
        }
69
    }
70
    unset($dirInfo);
71
    */
72
    /*
73
    //------------ START ----------------
74
    //------------------------------------------------------------------
75
    // Remove xsitemap.xml from XOOPS root folder if it exists
76
    //------------------------------------------------------------------
77
    $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml');
78
    if (\is_file($xmlfile)) {
79
        if (false === ($delOk = \unlink($xmlfile))) {
80
            $module->setErrors(\sprintf(\_AM_WGEVENTS_ERROR_BAD_REMOVE, $xmlfile));
81
        }
82
    }
83
    return $success && $delOk; // use this if you're using this routine
84
    */
85
86
    return $success;
87
    //------------ END  ----------------
88
}
89