Completed
Branch master (c921ab)
by Michael
109:50 queued 98:29
created

update_function.php ➔ xoops_module_update_extcal()   C

Complexity

Conditions 7
Paths 17

Size

Total Lines 73
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 34
c 2
b 0
f 0
nc 17
nop 2
dl 0
loc 73
rs 6.6896

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
/**
4
 * @param XoopsModule $xoopsModule
5
 * @param null        $oldVersion
6
 *
7
 * @return bool
8
 */
9
function xoops_module_update_extcal(XoopsModule $xoopsModule, $oldVersion = null)
0 ignored issues
show
Best Practice introduced by
The function xoops_module_update_extcal() has been defined more than once; this definition is ignored, only the first definition in include/onupdate.php (L73-185) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
10
{
11
    $newVersion = $xoopsModule->getVar('version') * 100;
12
    if ($newVersion == $oldVersion) {
13
        return true;
14
    }
15
16
    //----------------------------------------------------------
17
    // Create eXtCal upload directory
18
    $indexFile = __DIR__.'/index.html';
19
20
    $dir = XOOPS_ROOT_PATH.'/uploads/extcal';
21
    if (!is_dir($dir)) {
22
        mkdir($dir, 0777);
23
        copy($indexFile, $dir.'/index.html');
24
    }
25
26
    $dir = XOOPS_ROOT_PATH.'/uploads/extcal/etablissement';
27
    if (!is_dir($dir)) {
28
        mkdir($dir, 0777);
29
        copy($indexFile, $dir.'/index.html');
30
    }
31
    //------------------------------------------------------------
32
33
    $fld = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/versions/';
34
    $cls = 'extcal_%1$s';
35
36
    $version = array(
37
        '2_04' => 204,
38
        '2_15' => 215,
39
        '2_21' => 221,
40
        '2_28' => 228,
41
        '2_29' => 229,
42
        '2_33' => 233,
43
        '2_34' => 234,
44
        '2_35' => 235,
45
        '2_37' => 237,
46
    );
47
48 View Code Duplication
    while (list($key, $val) = each($version)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
        if ($oldVersion < $val) {
50
            $name = sprintf($cls, $key);
51
            $f = $fld.$name.'.php';
52
            //ext_echo ("<hr>{$f}<hr>");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
            if (is_readable($f)) {
54
                echo "mise à jour version : {$key} = {$val}<br>";
55
                include_once $f;
56
                $cl = new $name($xoopsModule, array('oldVersion' => $oldVersion));
0 ignored issues
show
Unused Code introduced by
$cl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
            }
58
        }
59
    }
60
61
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
        //$db = Database::getInstance();
63
        $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
64
65
        $sql = "ALTER TABLE `".$db->prefix('extcal_event')."` ADD `event_organisateur` varchar( 255 ) NOT NULL AFTER `event_desc` ;";
66
        $db->query($sql);
67
        ///////////
68
        // Create eXtcal upload directory
69
        $dir = XOOPS_ROOT_PATH."/uploads/extcal/etablissement";
70
        if(!is_dir($dir))
71
            mkdir($dir, 0777);
72
            chmod($dir, 0777);
73
74
        // Copy index.html files on uploads folders
75
        $indexFile = XOOPS_ROOT_PATH."/modules/extcal/include/index.html";
76
        copy($indexFile, XOOPS_ROOT_PATH."/uploads/extcal/etablissement/index.html");
77
78
        */
79
80
    return true;
81
}
82