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