Completed
Push — master ( f9ec10...603564 )
by Michael
02:48
created

ExtgalleryUtility::recurseCopy()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 2
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
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 8 and the first side effect is on line 3.

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
include_once __DIR__ . '/../include/config.php';
4
5
/**
6
 * Class ExtgalleryUtility
7
 */
8
class ExtgalleryUtility extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
12
     *
13
     * @param string $folder The full path of the directory to check
14
     *
15
     * @return void
16
     */
17
    public static function createFolder($folder)
18
    {
19
        try {
20
            if (!file_exists($folder)) {
21
                if (!mkdir($folder) && !is_dir($folder)) {
22
                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
23
                } else {
24
                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
25
                }
26
            }
27
        } catch (Exception $e) {
28
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
29
        }
30
    }
31
32
    /**
33
     * @param $file
34
     * @param $folder
35
     * @return bool
36
     */
37
    public static function copyFile($file, $folder)
38
    {
39
        return copy($file, $folder);
40
        //        try {
41
        //            if (!is_dir($folder)) {
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...
42
        //                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
43
        //            } else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
44
        //                return copy($file, $folder);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
45
        //            }
46
        //        } catch (Exception $e) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
47
        //            echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>";
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...
48
        //        }
49
        //        return false;
50
    }
51
52
    /**
53
     * @param $src
54
     * @param $dst
55
     */
56
    public static function recurseCopy($src, $dst)
57
    {
58
        $dir = opendir($src);
59
        //    @mkdir($dst);
60
        while (false !== ($file = readdir($dir))) {
61
            if (($file !== '.') && ($file !== '..')) {
62
                if (is_dir($src . '/' . $file)) {
63
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
64
                } else {
65
                    copy($src . '/' . $file, $dst . '/' . $file);
66
                }
67
            }
68
        }
69
        closedir($dir);
70
    }
71
72
    /**
73
     *
74
     * Verifies XOOPS version meets minimum requirements for this module
75
     * @static
76
     * @param XoopsModule $module
77
     *
78
     * @return bool true if meets requirements, false if not
79
     */
80
    public static function checkVerXoops(XoopsModule $module)
81
    {
82
        xoops_loadLanguage('admin', $module->dirname());
83
        //check for minimum XOOPS version
84
        $currentVer  = substr(XOOPS_VERSION, 6); // get the numeric part of string
85
        $currArray   = explode('.', $currentVer);
86
        $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
87
        $reqArray    = explode('.', $requiredVer);
88
        $success     = true;
89
        foreach ($reqArray as $k => $v) {
90
            if (isset($currArray[$k])) {
91
                if ($currArray[$k] > $v) {
92
                    break;
93
                } elseif ($currArray[$k] == $v) {
94
                    continue;
95
                } else {
96
                    $success = false;
97
                    break;
98
                }
99
            } else {
100
                if ((int)$v > 0) { // handles things like x.x.x.0_RC2
101
                    $success = false;
102
                    break;
103
                }
104
            }
105
        }
106
107
        if (!$success) {
108
            $module->setErrors(sprintf(_AM_TAG_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
109
        }
110
111
        return $success;
112
    }
113
114
    /**
115
     *
116
     * Verifies PHP version meets minimum requirements for this module
117
     * @static
118
     * @param XoopsModule $module
119
     *
120
     * @return bool true if meets requirements, false if not
121
     */
122
    public static function checkVerPhp(XoopsModule $module)
123
    {
124
        xoops_loadLanguage('admin', $module->dirname());
125
        // check for minimum PHP version
126
        $success = true;
127
        $verNum  = phpversion();
128
        $reqVer  =& $module->getInfo('min_php');
129
        if (false !== $reqVer && '' !== $reqVer) {
130
            if (version_compare($verNum, $reqVer, '<')) {
131
                $module->setErrors(sprintf(_AM_TAG_ERROR_BAD_PHP, $reqVer, $verNum));
132
                $success = false;
133
            }
134
        }
135
136
        return $success;
137
    }
138
139
    /**
140
     * @param $option
141
     * @return bool|mixed
142
     */
143 View Code Duplication
    public static function getModuleOption($option)
0 ignored issues
show
Duplication introduced by
This method 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...
144
    {
145
        global $xoopsModuleConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
146
        static $tbloptions = array();
147
        if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) {
148
            return $tbloptions[$option];
149
        }
150
151
        $retval = false;
152
        if (isset($xoopsModuleConfig)
153
            && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') === 'extgallery'
154
                && $xoopsModule->getVar('isactive'))
155
        ) {
156
            if (isset($xoopsModuleConfig[$option])) {
157
                $retval = $xoopsModuleConfig[$option];
158
            }
159
        } else {
160
            /** @var XoopsModuleHandler $moduleHandler */
161
            $moduleHandler = xoops_getHandler('module');
162
            $module        = $moduleHandler->getByDirname('extgallery');
163
164
            /** @var XoopsConfigHandler $configHandler */
165
            $configHandler = xoops_getHandler('config');
166
            if ($module) {
167
                $configurator =& $configHandler->getConfigsByCat(0, $module->getVar('mid'));
168
                if (isset($configurator[$option])) {
169
                    $retval = $configurator[$option];
170
                }
171
            }
172
        }
173
        $tbloptions[$option] = $retval;
174
175
        return $retval;
176
    }
177
178
    /**
179
     * @param $caption
180
     * @param $name
181
     * @param $value
182
     * @param $rows
183
     * @param $cols
184
     * @param $width
185
     * @param $height
186
     * @param $supplemental
187
     *
188
     * @return bool|XoopsFormEditor
189
     */
190 View Code Duplication
    public static function getWysiwygForm($caption, $name, $value, $rows, $cols, $width, $height, $supplemental)
0 ignored issues
show
Duplication introduced by
This method 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...
191
    {
192
        $editor_option            = strtolower(static::getModuleOption('form_options'));
193
        $editor                   = false;
0 ignored issues
show
Unused Code introduced by
$editor 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...
194
        $editor_configs           = array();
195
        $editor_configs['name']   = $name;
196
        $editor_configs['value']  = $value;
197
        $editor_configs['rows']   = $rows;
198
        $editor_configs['cols']   = $cols;
199
        $editor_configs['width']  = $width;
200
        $editor_configs['height'] = $height;
201
        $editor_configs['editor'] = $editor_option;
202
203
        $editor = new XoopsFormEditor($caption, $name, $editor_configs);
204
205
        return $editor;
206
    }
207
}
208