Completed
Push — master ( dc199a...eefcac )
by Michael
01:34
created

oninstall.inc.php ➔ xoops_module_pre_install_mylinks_base()   B

Complexity

Conditions 9
Paths 16

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
nc 16
nop 1
dl 0
loc 54
rs 7.448
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
 * Mylinks install functions.php
4
 *
5
 * LICENSE
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 *
11
 * @copyright:: {@link http://xoops.org/ XOOPS Project}
12
 * @license  ::    {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
13
 * @package  ::   mylinks
14
 * @author   ::    zyspec ([email protected])
15
 */
16
17
$moduleDirName = basename(dirname(__DIR__));
18
19
/**
20
 * @param $xoopsModule
21
 * @return bool
22
 */
23
function xoops_module_pre_install_mylinks_base(&$xoopsModule)
24
{
25
    global $xoopsDB;
26
    $retVal = true;
27
28
    $minPHPVersion   = $xoopsModule->getInfo('min_php');
29
    $minSQLVersion   = $xoopsModule->getInfo('min_sql');
30
    $minXoopsVersion = $xoopsModule->getInfo('min_xoops');
31
32
    /*
33
     * Error Messages
34
     */
35
    $phpErrMsg   = "<span style='color: red; font-weight: bold;'>YOUR PHP VERSION MUST BE UPGRADED TO AT LEAST VERSION {$minPHPVersion} TO USE THIS MODULE</span>";
36
    $mysqlErrMsg = "<span style='color: red; font-weight: bold;'>YOUR MYSQL DATABASE VERSION MUST BE UPGRADED TO AT LEAST VERSION {$minSQLVersion} TO USE THIS MODULE</span>";
37
    $xoopsErrMsg = "<span style='color: red; font-weight: bold;'>YOUR XOOPS VERSION MUST BE UPGRADED TO AT LEAST VERSION {$minXoopsVersion} TO USE THIS MODULE</span>";
38
39
    // Check if PHP version is supported
40
    if (version_compare(PHP_VERSION, $minPHPVersion) < 0) {
41
        $retVal = false;
42
        $xoopsModule->setErrors($phpErrMsg);
43
    } else {
44
        // Check if MySQL version is supported
45
        $minSQLSupported = explode('.', $minSQLVersion);
46
        $sql             = $xoopsDB->query('SELECT version() AS sqlver');
47
        $result          = $xoopsDB->fetchObject($sql);
48
        $currSQLVer      = $result->sqlver;
49
        $sqlVerArray     = explode('.', $currSQLVer);
50
        $sqlVerArray     = array_map('intval', $sqlVerArray); //strip off non-integer revision chars
51
52
        if ($sqlVerArray[0] < $minSQLSupported[0]) {
53
            $retVal = false;
54
            $xoopsModule->setErrors($mysqlErrMsg);
55
        } elseif ($sqlVerArray[0] == $minSQLSupported[0]) {
56
            if ($sqlVerArray[1] < $minSQLSupported[1]) {
57
                $retVal = false;
58
                $xoopsModule->setErrors($mysqlErrMsg);
59
            } elseif (($sqlVerArray[1] == $minSQLSupported[1]) && ($sqlVerArray[2] < $minSQLSupported[2])) {
60
                $retVal = false;
61
                $xoopsModule->setErrors($mysqlErrMsg);
62
            }
63
        }
64
65
        if ($retVal) {
66
            // Check if this XOOPS version is supported
67
            $curXoopsVersion     = substr(XOOPS_VERSION, 6);
68
            if (version_compare($curXoopsVersion, $minXoopsVersion, '<')) {
69
                $retVal = false;
70
                $xoopsModule->setErrors(sprintf($xoopsErrMsg, $minXoopsVersion, $curXoopsVersion));
71
            }
72
        }
73
    }
74
75
    return $retVal;
76
}
77
78
/**
79
 * @param $xoopsModule
80
 * @return bool
81
 */
82
function xoops_module_install_mylinks_base(&$xoopsModule)
0 ignored issues
show
Unused Code introduced by
The parameter $xoopsModule is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
{
84
    return true;
85
}
86
87
/**
88
 * eval functions to support module relocation (directory renaming)
89
 */
90
eval('function xoops_module_install_' . $moduleDirName . '(&$module=NULL)
91
        {
92
        return xoops_module_install_mylinks_base($module);
93
        }
94
    ');
95
eval('function xoops_module_pre_install_' . $moduleDirName . '(&$module=NULL)
96
        {
97
        return xoops_module_pre_install_mylinks_base($module);
98
        }
99
    ');
100