xoops_module_update_animal()   C
last analyzed

Complexity

Conditions 11
Paths 243

Size

Total Lines 50
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 32
c 0
b 0
f 0
nc 243
nop 0
dl 0
loc 50
rs 5.9458

How to fix   Complexity   

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
 * Verify that a mysql table exists
5
 *
6
 * @param $tablename
7
 *
8
 * @return bool
9
 * @copyright (c) Hervé Thouzard
10
 *
11
 * @package       News
12
 * @author        Hervé Thouzard (http://www.herve-thouzard.com)
13
 */
14
{
15
    global $xoopsDB;
16
    $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
17
18
    return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0);
19
}
20
21
/**
22
 * @return bool
23
 */
24
function xoops_module_update_animal()
25
{
26
    global $xoopsDB;
27
28
    if (Utility::tableExists($GLOBALS['xoopsDB']->prefix('owner'))) {
0 ignored issues
show
Bug introduced by
The type Utility 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...
29
        $sql    = sprintf('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('owner') . ' RENAME ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner'));
30
        $result = $GLOBALS['xoopsDB']->queryF($sql);
31
        if (!$result) {
32
            echo '<br>' . _AM_PEDIGREE_UPGRADEFAILED . ' ' . _AM_PEDIGREE_UPGRADEFAILED2;
33
            ++$errors;
34
        }
35
    }
36
37
    if (Utility::tableExists($GLOBALS['xoopsDB']->prefix('stamboom'))) {
38
        $sql    = sprintf('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('stamboom') . ' RENAME ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry'));
39
        $result = $GLOBALS['xoopsDB']->queryF($sql);
40
        if (!$result) {
41
            echo '<br>' . _AM_PEDIGREE_UPGRADEFAILED . ' ' . _AM_PEDIGREE_UPGRADEFAILED2;
42
            ++$errors;
43
        }
44
    }
45
46
    if (Utility::tableExists($GLOBALS['xoopsDB']->prefix('pedigree_fields'))) {
47
        $sql    = sprintf('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' RENAME ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields'));
48
        $result = $GLOBALS['xoopsDB']->queryF($sql);
49
        if (!$result) {
50
            echo '<br>' . _AM_PEDIGREE_UPGRADEFAILED . ' ' . _AM_PEDIGREE_UPGRADEFAILED2;
51
            ++$errors;
52
        }
53
    }
54
55
    if (Utility::tableExists($GLOBALS['xoopsDB']->prefix('pedigree_temp'))) {
56
        $sql    = sprintf('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' RENAME ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp'));
57
        $result = $GLOBALS['xoopsDB']->queryF($sql);
58
        if (!$result) {
59
            echo '<br>' . _AM_PEDIGREE_UPGRADEFAILED . ' ' . _AM_PEDIGREE_UPGRADEFAILED2;
60
            ++$errors;
61
        }
62
    }
63
64
    if (Utility::tableExists($GLOBALS['xoopsDB']->prefix('pedigree_trash'))) {
65
        $sql    = sprintf('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash') . ' RENAME ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash'));
66
        $result = $GLOBALS['xoopsDB']->queryF($sql);
67
        if (!$result) {
68
            echo '<br>' . _AM_PEDIGREE_UPGRADEFAILED . ' ' . _AM_PEDIGREE_UPGRADEFAILED2;
69
            ++$errors;
70
        }
71
    }
72
73
    return true;
74
}
75