Code Duplication    Length = 29-31 lines in 2 locations

class/Common/FilesManagement.php 2 locations

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