xoops_module_update_vs_executesql()   B
last analyzed

Complexity

Conditions 11
Paths 4

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 19
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 29
rs 7.3166

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 declare(strict_types=1);
2
3
/**
4
 * @param $module
5
 * @return bool
6
 */
7
function xoops_module_update_songlist(&$module): bool
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

7
function xoops_module_update_songlist(/** @scrutinizer ignore-unused */ &$module): bool

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...
8
{
9
    $sql = [];
10
11
    $sql[] = 'CREATE TABLE `'
12
             . $GLOBALS['xoopsDB']->prefix('songlist_voice')
13
             . "` (  `vcid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,  `name` VARCHAR(128) DEFAULT NULL,  `artists` INT(12) UNSIGNED DEFAULT '0',  `albums` INT(12) UNSIGNED DEFAULT '0',  `songs` INT(12) UNSIGNED DEFAULT '0',  `rank` DECIMAL(10,3) UNSIGNED DEFAULT '0.000',  `votes` INT(10) UNSIGNED DEFAULT '0',  `created` INT(12) UNSIGNED DEFAULT '0',  `updated` INT(12) UNSIGNED DEFAULT '0',  PRIMARY KEY (`vcid`),  KEY `SORT` (`name`(32),`rank`,`votes`,`created`)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
14
    $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `vcid` INT(12) UNSIGNED DEFAULT '0'";
15
    $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `lyrics` `lyrics` LONGTEXT';
16
    $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `mp3` VARCHAR(500) DEFAULT ''";
17
    $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `traxid` `traxid` INT(4) UNSIGNED ZEROFILL DEFAULT NULL';
18
19
    return xoops_module_update_vs_executesql($sql);
20
}
21
22
/**
23
 * @param $sql
24
 * @return bool
25
 */
26
function xoops_module_update_vs_executesql($sql): bool
27
{
28
    if (is_string($sql)) {
29
        if ($GLOBALS['xoopsDB']->queryF($sql)) {
30
            xoops_error($sql, 'SQL Executed Successfully!!!');
31
        }
32
    } elseif (is_array($sql)) {
33
        foreach ($sql as $id => $question) {
34
            if (is_array($question)) {
35
                foreach ($question as $kquestion => $questionb) {
36
                    if ($GLOBALS['xoopsDB']->queryF($kquestion)) {
37
                        xoops_error($kquestion, 'SQL Executed Successfully!!!');
38
                        xoops_module_update_vs_executesql($questionb);
39
                    }
40
                }
41
            } elseif ($GLOBALS['xoopsDB']->queryF($id)) {
42
                    xoops_error($id, 'SQL Executed Successfully!!!');
43
                    if ($GLOBALS['xoopsDB']->queryF($question)) {
44
                        xoops_error($question, 'SQL Executed Successfully!!!');
45
                    }
46
                } elseif ($GLOBALS['xoopsDB']->queryF($question)) {
47
                    xoops_error($question, 'SQL Executed Successfully!!!');
48
            }
49
        }
50
    } else {
51
        return false;
52
    }
53
54
    return true;
55
}
56