XoopsModules25x /
tdmdownloads
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace XoopsModules\Tdmdownloads\Common; |
||||
| 4 | |||||
| 5 | /* |
||||
| 6 | You may not change or alter any portion of this comment or credits |
||||
| 7 | of supporting developers from this source code or any supporting source code |
||||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||||
| 9 | |||||
| 10 | This program is distributed in the hope that it will be useful, |
||||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
| 13 | */ |
||||
| 14 | |||||
| 15 | /** |
||||
| 16 | * @copyright XOOPS Project (https://xoops.org) |
||||
| 17 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||||
| 18 | * @author mamba <[email protected]> |
||||
| 19 | */ |
||||
| 20 | trait VersionChecks |
||||
| 21 | { |
||||
| 22 | /** |
||||
| 23 | * Verifies XOOPS version meets minimum requirements for this module |
||||
| 24 | * @static |
||||
| 25 | * @param \XoopsModule|null $module |
||||
| 26 | * |
||||
| 27 | * @param null|string $requiredVer |
||||
| 28 | * @return bool true if meets requirements, false if not |
||||
| 29 | */ |
||||
| 30 | public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
||||
| 31 | { |
||||
| 32 | $moduleDirName = basename(dirname(__DIR__)); |
||||
| 33 | if (null === $module) { |
||||
| 34 | $module = \XoopsModule::getByDirname($moduleDirName); |
||||
| 35 | } |
||||
| 36 | xoops_loadLanguage('admin', $moduleDirName); |
||||
| 37 | |||||
| 38 | //check for minimum XOOPS version |
||||
| 39 | $currentVer = mb_substr(XOOPS_VERSION, 6); // get the numeric part of string |
||||
| 40 | if (null === $requiredVer) { |
||||
| 41 | $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 42 | } |
||||
| 43 | $success = true; |
||||
| 44 | |||||
| 45 | if (version_compare($currentVer, $requiredVer, '<')) { |
||||
| 46 | $success = false; |
||||
| 47 | $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
||||
|
0 ignored issues
–
show
|
|||||
| 48 | } |
||||
| 49 | |||||
| 50 | return $success; |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * Verifies PHP version meets minimum requirements for this module |
||||
| 55 | * @static |
||||
| 56 | * @param \XoopsModule $module |
||||
| 57 | * |
||||
| 58 | * @return bool true if meets requirements, false if not |
||||
| 59 | */ |
||||
| 60 | public static function checkVerPhp(\XoopsModule $module) |
||||
| 61 | { |
||||
| 62 | $moduleDirName = basename(dirname(dirname(__DIR__))); |
||||
| 63 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||||
|
0 ignored issues
–
show
|
|||||
| 64 | xoops_loadLanguage('admin', $module->dirname()); |
||||
|
0 ignored issues
–
show
It seems like
$module->dirname() can also be of type array and array; however, parameter $domain of xoops_loadLanguage() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 65 | // check for minimum PHP version |
||||
| 66 | $success = true; |
||||
| 67 | $verNum = PHP_VERSION; |
||||
| 68 | $reqVer = $module->getInfo('min_php'); |
||||
| 69 | if (false !== $reqVer && '' !== $reqVer) { |
||||
| 70 | if (version_compare($verNum, $reqVer, '<')) { |
||||
|
0 ignored issues
–
show
It seems like
$reqVer can also be of type array; however, parameter $version2 of version_compare() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 71 | $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum)); |
||||
|
0 ignored issues
–
show
It seems like
$reqVer can also be of type array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 72 | $success = false; |
||||
| 73 | } |
||||
| 74 | } |
||||
| 75 | |||||
| 76 | return $success; |
||||
| 77 | } |
||||
| 78 | } |
||||
| 79 |