Utility   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 52
rs 10
c 2
b 0
f 0
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A recurseCopy() 0 14 5
A createFolder() 0 21 5
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Contact;
4
5
use RuntimeException;
6
7
/**
8
 * Class Utility
9
 */
10
class Utility extends Common\SysUtility
11
{
12
    //--------------- Custom module methods -----------------------------
13
    /**
14
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
15
     *
16
     * @param string $folder The full path of the directory to check
17
     *
18
     * @return void
19
     */
20
    public static function createFolder($folder): void
21
    {
22
        //        try {
23
        //            if (!mkdir($folder) && !is_dir($folder)) {
24
        //                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
25
        //            } else {
26
        //                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
27
        //            }
28
        //        }
29
        //        catch (Exception $e) {
30
        //            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
31
        //        }
32
        try {
33
            if (!\is_dir($folder)) {
34
                if (!\mkdir($folder) && !\is_dir($folder)) {
35
                    throw new RuntimeException(\sprintf('Unable to create the %s directory', $folder));
36
                }
37
                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
38
            }
39
        } catch (\Exception $e) {
40
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
41
        }
42
    }
43
44
    /**
45
     * @param $src
46
     * @param $dst
47
     */
48
    public static function recurseCopy($src, $dst): void
49
    {
50
        $dir = \opendir($src);
51
        //    @mkdir($dst);
52
        while (false !== ($file = \readdir($dir))) {
53
            if (('.' !== $file) && ('..' !== $file)) {
54
                if (\is_dir($src . '/' . $file)) {
55
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
56
                } else {
57
                    \copy($src . '/' . $file, $dst . '/' . $file);
58
                }
59
            }
60
        }
61
        \closedir($dir);
62
    }
63
64
    /**
65
     * Verifies XOOPS version meets minimum requirements for this module
66
     * @static
67
     * @param \XoopsModule $module
68
     *
69
     * @return bool true if meets requirements, false if not
70
     */
71
    //    public static function checkVerXoops(XoopsModule $module)
72
    //    {
73
    //        $currentVersion  = strtolower(str_replace('XOOPS ', '', XOOPS_VERSION));
74
    //        $requiredVersion = strtolower($module->getInfo('min_xoops'));
75
    //        $vc              = version_compare($currentVersion, $requiredVersion);
76
    //        $success         = ($vc >= 0);
77
    //        if (false === $success) {
78
    //            xoops_loadLanguage('admin', $module->dirname());
79
    //            $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_XOOPS, $requiredVersion, $currentVersion));
80
    //        }
81
    //
82
    //        return $success;
83
    //    }
84
85
    /**
86
     * Verifies PHP version meets minimum requirements for this module
87
     * @static
88
     * @param \XoopsModule $module
89
     *
90
     * @return bool true if meets requirements, false if not
91
     */
92
    //    public static function checkVerPhp(XoopsModule $module)
93
    //    {
94
    //        xoops_loadLanguage('admin', $module->dirname());
95
    //        // check for minimum PHP version
96
    //        $success = true;
97
    //        $verNum  = PHP_VERSION;
98
    //        $reqVer  =& $module->getInfo('min_php');
99
    //        if (false !== $reqVer && '' !== $reqVer) {
100
    //            if (version_compare($verNum, $reqVer, '<')) {
101
    //                $module->setErrors(sprintf(_AM_CONTACT_ERROR_BAD_PHP, $reqVer, $verNum));
102
    //                $success = false;
103
    //            }
104
    //        }
105
    //
106
    //        return $success;
107
    //    }
108
}
109