xoops_module_update_lexikon_v152()   C
last analyzed

Complexity

Conditions 16
Paths 63

Size

Total Lines 57
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 16
eloc 35
nc 63
nop 1
dl 0
loc 57
rs 5.5666
c 3
b 0
f 0

How to fix   Long Method    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
// $Id$
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <https://xoops.org>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
//
28
29
//error_reporting(E_ALL);
30
31
use XoopsModules\Lexikon\{
32
    Helper,
33
    Common\Configurator,
34
    Utility
35
};
36
37
38
/**
39
 * @param      $module
40
 * @param null $prev_version
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prev_version is correct as it would always require null to be passed?
Loading history...
41
 * @return bool|null
42
 */
43
function xoops_module_update_lexikon($module, $prev_version = null)
44
{
45
    $moduleDirName      = \basename(\dirname(__DIR__));
46
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirNameUpper is dead and can be removed.
Loading history...
47
48
    $helper       = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
49
    $utility      = new Utility();
0 ignored issues
show
Unused Code introduced by
The assignment to $utility is dead and can be removed.
Loading history...
50
    $configurator = new Configurator();
0 ignored issues
show
Unused Code introduced by
The assignment to $configurator is dead and can be removed.
Loading history...
51
52
    $ret = null;
53
    if ($prev_version < 152) {
54
        $ret = xoops_module_update_lexikon_v152($module);
55
    }
56
    $errors = $module->getErrors();
57
    if (!empty($errors)) {
58
        print_r($errors);
59
    }
60
61
    return $ret;
62
}
63
64
/**
65
 * @param $xoopsModule
66
 * @return bool
67
 */
68
function xoops_module_update_lexikon_v152($xoopsModule)
0 ignored issues
show
Unused Code introduced by
The parameter $xoopsModule 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

68
function xoops_module_update_lexikon_v152(/** @scrutinizer ignore-unused */ $xoopsModule)

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...
69
{
70
    /**
71
     * Create default upload directories
72
     */
73
    // Copy base file
74
    $indexFile = XOOPS_UPLOAD_PATH . '/index.html';
75
    $blankFile = XOOPS_UPLOAD_PATH . '/blank.gif';
76
    // Making of uploads/lexikon folder
77
    $p_lexikon = XOOPS_UPLOAD_PATH . '/lexikon';
78
    if (!is_dir($p_lexikon)) {
79
        if (!mkdir($p_lexikon, 0777) && !is_dir($p_lexikon)) {
80
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $p_lexikon));
81
        }
82
        chmod($p_lexikon, 0777);
83
    }
84
    copy($indexFile, $p_lexikon . '/index.html');
85
    // Making of categories folder
86
    $pl_categories = $p_lexikon . '/categories';
87
    if (!is_dir($pl_categories)) {
88
        if (!mkdir($pl_categories, 0777) && !is_dir($pl_categories)) {
89
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $pl_categories));
90
        }
91
        chmod($pl_categories, 0777);
92
    }
93
    copy($indexFile, $pl_categories . '/index.html');
94
95
    $plc_images = $pl_categories . '/images';
96
    if (!is_dir($plc_images)) {
97
        if (!mkdir($plc_images, 0777) && !is_dir($plc_images)) {
98
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $plc_images));
99
        }
100
        chmod($plc_images, 0777);
101
    }
102
    copy($indexFile, $plc_images . '/index.html');
103
    copy($blankFile, $plc_images . '/blank.gif');
104
    // Making of entries folder
105
    $pl_entries = $p_lexikon . '/entries';
106
    if (!is_dir($pl_entries)) {
107
        if (!mkdir($pl_entries, 0777) && !is_dir($pl_entries)) {
108
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $pl_entries));
109
        }
110
        chmod($pl_entries, 0777);
111
    }
112
    copy($indexFile, $pl_entries . '/index.html');
113
114
    $ple_images = $pl_entries . '/images';
115
    if (!is_dir($ple_images)) {
116
        if (!mkdir($ple_images, 0777) && !is_dir($ple_images)) {
117
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $ple_images));
118
        }
119
        chmod($ple_images, 0777);
120
    }
121
    copy($indexFile, $ple_images . '/index.html');
122
    copy($blankFile, $ple_images . '/blank.gif');
123
124
    return true;
125
}
126