Passed
Push — master ( cf57bc...9eba79 )
by Michael
01:41
created

xoops_module_uninstall_gbook()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 48
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 16
nc 8
nop 1
dl 0
loc 48
rs 8.551
c 0
b 0
f 0
1
<?php
2
/**
3
 * uninstall.php - cleanup on module uninstall
4
 *
5
 * @author          XOOPS Module Development Team
6
 * @copyright       {@link https://xoops.org 2001-2016 XOOPS Project}
7
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
8
 * @link            https://xoops.org XOOPS
9
 */
10
11
12
/**
13
 * Prepares system prior to attempting to uninstall module
14
 * @param XoopsModule $module {@link XoopsModule}
15
 *
16
 * @return bool true if ready to uninstall, false if not
17
 */
18
19
use XoopsModules\Gbook;
20
21
function xoops_module_pre_uninstall_gbook(\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

21
function xoops_module_pre_uninstall_gbook(/** @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...
22
{
23
    // Do some synchronization
24
    return true;
25
}
26
27
/**
28
 *
29
 * Performs tasks required during uninstallation of the module
30
 * @param XoopsModule $module {@link XoopsModule}
31
 *
32
 * @return bool true if uninstallation successful, false if not
33
 */
34
function xoops_module_uninstall_gbook(\XoopsModule $module)
35
{
36
//    return true;
37
38
    $moduleDirName = basename(dirname(__DIR__));
39
    $xsitemapHelper      = \Xmf\Module\Helper::getHelper($moduleDirName);
0 ignored issues
show
Bug introduced by
The type Xmf\Module\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...
40
41
    /** @var Gbook\Utility $utilityClass */
42
    $utilityClass     = ucfirst($moduleDirName) . 'Utility';
43
    if (!class_exists($utilityClass)) {
0 ignored issues
show
Bug introduced by
$utilityClass of type XoopsModules\Gbook\Utility is incompatible with the type string expected by parameter $class_name of class_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
    if (!class_exists(/** @scrutinizer ignore-type */ $utilityClass)) {
Loading history...
44
        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

44
        /** @scrutinizer ignore-call */ 
45
        xoops_load('utility', $moduleDirName);
Loading history...
45
    }
46
47
    $success = true;
48
    $xsitemapHelper->loadLanguage('admin');
49
50
51
    //------------------------------------------------------------------
52
    // Remove uploads folder (and all subfolders) if they exist
53
    //------------------------------------------------------------------
54
55
    $old_directories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")];
56
    foreach ($old_directories as $old_dir) {
57
        $dirInfo = new \SplFileInfo($old_dir);
58
        if ($dirInfo->isDir()) {
59
            // The directory exists so delete it
60
            if (false === $utilityClass::rrmdir($old_dir)) {
61
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH'), $old_dir));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper does not exist. Did you maybe mean $module?
Loading history...
62
                $success = false;
63
            }
64
        }
65
        unset($dirInfo);
66
    }
67
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
68
    //------------ START ----------------
69
    //------------------------------------------------------------------
70
    // Remove xsitemap.xml from XOOPS root folder if it exists
71
    //------------------------------------------------------------------
72
    $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml');
73
    if (is_file($xmlfile)) {
74
        if (false === ($delOk = unlink($xmlfile))) {
75
            $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_REMOVE, $xmlfile));
76
        }
77
    }
78
//    return $success && $delOk; // use this if you're using this routine
79
*/
80
81
    return $success;
82
    //------------ END  ----------------
83
84
}
85
86