Completed
Push — master ( eb0f84...204b42 )
by Michael
02:55
created

module.php ➔ update_userlog_v100()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 16
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 24 and the first side effect is on line 22.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 *  userlog module
13
 *
14
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
16
 * @package         userlog include
17
 * @since           1
18
 * @author          irmtfan ([email protected])
19
 * @author          The XOOPS Project <www.xoops.org> <www.xoops.ir>
20
 * @version         $Id: module.php 1 2013-02-26 16:25:04Z irmtfan $
21
 */
22
defined("XOOPS_ROOT_PATH") or die("XOOPS root path not defined");
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
23
require_once dirname(__FILE__) . '/common.php';
24
function xoops_module_uninstall_userlog(&$module)
0 ignored issues
show
Unused Code introduced by
The parameter $module 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...
25
{
26
    $logsetObj = UserlogSetting::getInstance();
27
28
    return $logsetObj->cleanCache(); // delete all settings caches
29
}
30
function xoops_module_update_userlog(&$module, $prev_version = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
31
{
32
    if ($prev_version == round( $module->getInfo("version") * 100, 2 )) {
33
        $module->setErrors("You have the latest " . $module->getInfo("name") . " module (". $module->getInfo("dirname") . " version " . $module->getInfo("version") . ") and update is not necessary");
34
        print_r($module->getErrors());
35
36
        return true;
37
    }
38
    $ret = false;
39
    // first db update
40
    if ($prev_version == 100) {
41
        $ret = update_userlog_v100($module);
42
    }
43
    print_r($module->getErrors());
44
45
    return $ret;
46
}
47
48
// update database from v1 to 1.01 (Beta1 to RC1)
49
// module_name VARCHAR(25) change to VARCHAR(50)
50
function update_userlog_v100(&$module)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
51
{
52
    $field = "module_name";
53
    $Userlog = Userlog::getInstance();
54
    $ret = $Userlog->getHandler('log')->showFields($field);
55
    preg_match_all('!\d+!', $ret[$field]["Type"], $nums);
56
    // only change if module_name Type was VARCHAR(25)
57
    if($nums[0][0] == 25) {
58
        $ret2 = $Userlog->getHandler('log')->changeField($field, "VARCHAR(50)");
59
    } else {
60
        $ret2 = true;
61
        $module->setErrors("Your table field ({$field}) with size {$ret[$field]['Type']} dont need change.");
62
    }
63
64
    return $ret2;
65
}
66