Completed
Pull Request — master (#16)
by Michael
01:51
created

install_function.php ➔ xoops_module_pre_install_news()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
c 0
b 0
f 0
nc 7
nop 1
dl 0
loc 22
rs 6.9811
1
<?php
2
/**
3
 * News functions
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   {@link https://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Voltan
15
 * @package     News
16
 * @param $xoopsModule
17
 * @return bool
18
 */
19
20
function xoops_module_pre_install_news(XoopsModule $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...
21
{
22
    // Check if this XOOPS version is supported
23
    $minSupportedVersion = explode('.', '2.5.0');
24
    $currentVersion      = explode('.', substr(XOOPS_VERSION, 6));
25
26
    if ($currentVersion[0] > $minSupportedVersion[0]) {
27
        return true;
28
    } elseif ($currentVersion[0] == $minSupportedVersion[0]) {
29
        if ($currentVersion[1] > $minSupportedVersion[1]) {
30
            return true;
31
        } elseif ($currentVersion[1] == $minSupportedVersion[1]) {
32
            if ($currentVersion[2] > $minSupportedVersion[2]) {
33
                return true;
34
            } elseif ($currentVersion[2] == $minSupportedVersion[2]) {
35
                return true;
36
            }
37
        }
38
    }
39
40
    return false;
41
}
42
43
/**
44
 * @param XoopsModule $xoopsModule
45
 *
46
 * @return bool
47
 */
48
function xoops_module_install_news(XoopsModule $xoopsModule)
49
{
50
    $module_id     = $xoopsModule->getVar('mid');
51
    $gpermHandler  = xoops_getHandler('groupperm');
52
    $configHandler = xoops_getHandler('config');
0 ignored issues
show
Unused Code introduced by
$configHandler 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...
53
54
    /**
55
     * Default public category permission mask
56
     */
57
58
    // Access right
59
    $gpermHandler->addRight('news_approve', 1, XOOPS_GROUP_ADMIN, $module_id);
60
    $gpermHandler->addRight('news_submit', 1, XOOPS_GROUP_ADMIN, $module_id);
61
    $gpermHandler->addRight('news_view', 1, XOOPS_GROUP_ADMIN, $module_id);
62
63
    $gpermHandler->addRight('news_view', 1, XOOPS_GROUP_USERS, $module_id);
64
    $gpermHandler->addRight('news_view', 1, XOOPS_GROUP_ANONYMOUS, $module_id);
65
66
    $dir = XOOPS_ROOT_PATH . '/uploads/news';
67
    //    if (!is_dir($dir)) {
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...
68
    //        mkdir($dir, 0777);
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...
69
    //    }
70
71 View Code Duplication
    if (!@mkdir($dir) && !is_dir($dir)) {
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...
72
        throw new \RuntimeException('The directory ' . $dir . ' could not be created.');
73
    }
74
75
    chmod($dir, 0777);
76
77
    $dir = XOOPS_ROOT_PATH . '/uploads/news/file';
78 View Code Duplication
    if (!@mkdir($dir) && !is_dir($dir)) {
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...
79
        throw new \RuntimeException('The directory ' . $dir . ' could not be created.');
80
    }
81
    chmod($dir, 0777);
82
83
    $dir = XOOPS_ROOT_PATH . '/uploads/news/image';
84 View Code Duplication
    if (!@mkdir($dir) && !is_dir($dir)) {
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...
85
        throw new \RuntimeException('The directory ' . $dir . ' could not be created.');
86
    }
87
    chmod($dir, 0777);
88
89
    // Copy index.html files on uploads folders
90
    $indexFile = XOOPS_ROOT_PATH . '/modules/news/include/index.html';
91
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/index.html');
92
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/file/index.html');
93
    copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/image/index.html');
94
95
    return true;
96
}
97