Passed
Branch feature/php-docs2 (9f8cc0)
by Michael
04:49
created

protector_onuninstall_base()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 55
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 18
nc 4
nop 2
dl 0
loc 55
rs 9.0444
c 0
b 0
f 0

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
use XoopsModules\Protector;
4
use XoopsModules\Protector\Registry;
5
6
require_once __DIR__ . '/preloads/autoloader.php';
7
8
// start hack by Trabis
9
//if (!class_exists('Registry')) {
10
//    exit('Registry not found');
11
//}
12
13
$registry  = Registry::getInstance();
14
$mydirname = $registry->getEntry('mydirname');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $mydirname is correct as $registry->getEntry('mydirname') targeting XoopsModules\Protector\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
15
$mydirpath = $registry->getEntry('mydirpath');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $mydirpath is correct as $registry->getEntry('mydirpath') targeting XoopsModules\Protector\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
16
$language  = $registry->getEntry('language');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $language is correct as $registry->getEntry('language') targeting XoopsModules\Protector\Registry::getEntry() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
17
// end hack by Trabis
18
19
eval(' function xoops_module_uninstall_' . $mydirname . '( $module ) { return protector_onuninstall_base( $module , "' . $mydirname . '" ) ; } ');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
20
21
if (!function_exists('protector_onuninstall_base')) {
22
23
    /**
24
     * @param $module
25
     * @param $mydirname
26
     *
27
     * @return bool
28
     */
29
    function protector_onuninstall_base($module, $mydirname)
30
    {
31
        // transations on module uninstall
32
33
        global $ret; // TODO :-D
34
35
        // for Cube 2.1
36
//        if (defined('XOOPS_CUBE_LEGACY')) {
37
//            $root =& XCube_Root::getSingleton();
38
//            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUninstall.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onuninstall');
39
//            $ret = array();
40
//        } else {
41
            if (!is_array($ret)) {
42
                $ret = array();
43
            }
44
//        }
45
46
        $db  = XoopsDatabaseFactory::getDatabaseConnection();
47
        $mid = $module->getVar('mid');
0 ignored issues
show
Unused Code introduced by
The assignment to $mid is dead and can be removed.
Loading history...
48
49
        // TABLES (loading mysql.sql)
50
        $sql_file_path = __DIR__ . '/sql/mysql.sql';
51
        $prefix_mod    = $db->prefix() . '_' . $mydirname;
52
        if (file_exists($sql_file_path)) {
53
            $ret[]     = 'SQL file found at <b>' . htmlspecialchars($sql_file_path) . '</b>.<br  /> Deleting tables...<br>';
54
            $sql_lines = file($sql_file_path);
55
            foreach ($sql_lines as $sql_line) {
56
                if (preg_match('/^CREATE TABLE \`?([a-zA-Z0-9_-]+)\`? /i', $sql_line, $regs)) {
57
                    $sql = 'DROP TABLE ' . addslashes($prefix_mod . '_' . $regs[1]);
58
                    if (!$db->query($sql)) {
0 ignored issues
show
Bug introduced by
The method query() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

58
                    if (!$db->/** @scrutinizer ignore-call */ query($sql)) {
Loading history...
59
                        $ret[] = '<span style="color:#ff0000;">ERROR: Could not drop table <b>' . htmlspecialchars($prefix_mod . '_' . $regs[1]) . '<b>.</span><br>';
60
                    } else {
61
                        $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $regs[1]) . '</b> dropped.<br>';
62
                    }
63
                }
64
            }
65
        }
66
67
        // TEMPLATES (Not necessary because modulesadmin removes all templates)
68
        /* $tplfile_handler = xoops_getHandler( 'tplfile' ) ;
69
        $templates =& $tplfile_handler->find( null , 'module' , $mid ) ;
70
        $tcount = count( $templates ) ;
71
        if ($tcount > 0) {
72
            $ret[] = 'Deleting templates...' ;
73
            for ($i = 0 ; $i < $tcount ; ++$i) {
74
                if ( ! $tplfile_handler->delete( $templates[$i] ) ) {
75
                    $ret[] = '<span style="color:#ff0000;">ERROR: Could not delete template '.$templates[$i]->getVar('tpl_file','s').' from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id','s').'</b></span><br>';
76
                } else {
77
                    $ret[] = 'Template <b>'.$templates[$i]->getVar('tpl_file','s').'</b> deleted from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id','s').'</b><br>';
78
                }
79
            }
80
        }
81
        unset($templates); */
82
83
        return true;
84
    }
85
86
    /**
87
     * @param $module_obj
88
     * @param $log
89
     */
90
    function protector_message_append_onuninstall(&$module_obj, &$log)
0 ignored issues
show
Unused Code introduced by
The parameter $module_obj 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

90
    function protector_message_append_onuninstall(/** @scrutinizer ignore-unused */ &$module_obj, &$log)

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...
91
    {
92
        if (is_array(@$GLOBALS['ret'])) {
93
            foreach ($GLOBALS['ret'] as $message) {
94
                $log->add(strip_tags($message));
95
            }
96
        }
97
98
        // use mLog->addWarning() or mLog->addError() if necessary
99
    }
100
}
101