Code Duplication    Length = 28-31 lines in 2 locations

class/common/FilesManagement.php 2 locations

@@ 221-251 (lines=31) @@
218
     *
219
     * @return bool true on success
220
     */
221
    public static function rmove($src, $dest)
222
    {
223
        // Only continue if user is a 'global' Admin
224
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
225
            return false;
226
        }
227
228
        // If source is not a directory stop processing
229
        if (!is_dir($src)) {
230
            return false;
231
        }
232
233
        // If the destination directory does not exist and could not be created stop processing
234
        if (!is_dir($dest) && !mkdir($dest, 0755)) {
235
            return false;
236
        }
237
238
        // Open the source directory to read in files
239
        $iterator = new \DirectoryIterator($src);
240
        foreach ($iterator as $fObj) {
241
            if ($fObj->isFile()) {
242
                rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
243
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
244
                // Try recursively on directory
245
                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
246
                //                rmdir($fObj->getPath()); // now delete the directory
247
            }
248
        }
249
        $iterator = null;   // clear iterator Obj to close file/directory
250
        return rmdir($src); // remove the directory & return results
251
    }
252
253
    /**
254
     * Recursively copy directories and files from one directory to another
@@ 264-291 (lines=28) @@
261
     *
262
     * @return bool true on success
263
     */
264
    public static function rcopy($src, $dest)
265
    {
266
        // Only continue if user is a 'global' Admin
267
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
268
            return false;
269
        }
270
271
        // If source is not a directory stop processing
272
        if (!is_dir($src)) {
273
            return false;
274
        }
275
276
        // If the destination directory does not exist and could not be created stop processing
277
        if (!is_dir($dest) && !mkdir($dest, 0755)) {
278
            return false;
279
        }
280
281
        // Open the source directory to read in files
282
        $iterator = new \DirectoryIterator($src);
283
        foreach ($iterator as $fObj) {
284
            if ($fObj->isFile()) {
285
                copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
286
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
287
                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
288
            }
289
        }
290
        return true;
291
    }
292
}
293