Completed
Push — master ( 46e288...43eac3 )
by Michael
12s
created

install.php ➔ xoosocialnetwork_copyfile()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 5
nop 3
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Xoosocialnetwork module
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       The XOOPS Project http://sourceforge.net/projects/xoops/
13
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @package         Xoosocialnetwork
15
 * @since           2.6.0
16
 * @author          Laurent JEN (Aka DuGris)
17
 */
18
19
/**
20
 * @return bool
21
 */
22
function xoops_module_install_xoosocialnetwork()
23
{
24
    $xoops     = Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
$xoops 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...
25
    $folders   = array();
26
    $folders[] = \XoopsBaseConfig::get('uploads-path') . '/xoosocialnetwork/images';
27
    $images    = array(
28
        'index.html',
29
        'blank.gif');
30
31
    foreach ($folders as $folder) {
32
        if (!xoosocialnetwork_mkdirs($folder)) {
33
            return false;
34
        } else {
35
            foreach ($images as $image) {
36
                if (!xoosocialnetwork_copyfile(\XoopsBaseConfig::get('uploads-path'), $image, $folder)) {
37
                    return false;
38
                }
39
            }
40
        }
41
    }
42
43
    return true;
44
}
45
46
/**
47
 * @param              $pathname
48
 * @param mixed|string $pathout
49
 * @return bool
50
 */
51 View Code Duplication
function xoosocialnetwork_mkdirs($pathname, $pathout = XOOPS_ROOT_PATH)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
52
{
53
    $xoops    = Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
$xoops 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...
54
    $pathname = substr($pathname, strlen(\XoopsBaseConfig::get('root-path')));
55
    $pathname = str_replace(DIRECTORY_SEPARATOR, '/', $pathname);
56
57
    $dest  = $pathout;
58
    $paths = explode('/', $pathname);
59
60
    foreach ($paths as $path) {
61
        if (!empty($path)) {
62
            $dest = $dest . '/' . $path;
63
            if (!is_dir($dest)) {
64
                if (!mkdir($dest, 0755)) {
65
                    return false;
66
                } else {
67
                    xoosocialnetwork_copyfile(\XoopsBaseConfig::get('uploads-path'), 'index.html', $dest);
68
                }
69
            }
70
        }
71
    }
72
73
    return true;
74
}
75
76
/**
77
 * @param $folder_in
78
 * @param $source_file
79
 * @param $folder_out
80
 * @return bool
81
 */
82 View Code Duplication
function xoosocialnetwork_copyfile($folder_in, $source_file, $folder_out)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
83
{
84
    if (!is_dir($folder_out)) {
85
        if (!xoosocialnetwork_mkdirs($folder_out)) {
86
            return false;
87
        }
88
    }
89
90
    // Simple copy for a file
91
    if (is_file($folder_in . '/' . $source_file)) {
92
        return copy($folder_in . '/' . $source_file, $folder_out . '/' . basename($source_file));
93
    }
94
95
    return false;
96
}
97