VersionChecks::checkVerXoops()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 8
nop 2
dl 0
loc 22
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Countdown\Common;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * Module: Countdown
19
 *
20
 * @category        Module
21
 * @package         countdown
22
 * @author          XOOPS Development Team <https://xoops.org>
23
 * @copyright       {@link https://xoops.org/ XOOPS Project}
24
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
25
 * @link            https://xoops.org/
26
 * @since           1.0.0
27
 */
28
trait VersionChecks
29
{
30
    /**
31
     *
32
     * Verifies XOOPS version meets minimum requirements for this module
33
     * @static
34
     * @param \XoopsModule $module
35
     *
36
     * @param null|string  $requiredVer
37
     * @return bool true if meets requirements, false if not
38
     */
39
    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null)
40
    {
41
        $moduleDirName      = basename(dirname(dirname(__DIR__)));
42
        $moduleDirNameUpper = strtoupper($moduleDirName);
43
        if (null === $module) {
44
            $module = \XoopsModule::getByDirname($moduleDirName);
45
        }
46
        xoops_loadLanguage('admin', $moduleDirName);
47
48
        //check for minimum XOOPS version
49
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
50
        if (null === $requiredVer) {
51
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('min_xoops') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
            $requiredVer = '' . /** @scrutinizer ignore-type */ $module->getInfo('min_xoops'); //making sure it's a string
Loading history...
52
        }
53
        $success = true;
54
55
        if (version_compare($currentVer, $requiredVer, '<')) {
56
            $success = false;
57
            $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
58
        }
59
60
        return $success;
61
    }
62
63
    /**
64
     *
65
     * Verifies PHP 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 checkVerPhp(\XoopsModule $module)
72
    {
73
        $moduleDirName      = basename(dirname(dirname(__DIR__)));
74
        $moduleDirNameUpper = strtoupper($moduleDirName);
75
        xoops_loadLanguage('admin', $module->dirname());
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

75
        xoops_loadLanguage('admin', /** @scrutinizer ignore-type */ $module->dirname());
Loading history...
76
        // check for minimum PHP version
77
        $success = true;
78
        $verNum  = PHP_VERSION;
79
        $reqVer  = $module->getInfo('min_php');
80
        if (false !== $reqVer && '' !== $reqVer) {
81
            if (version_compare($verNum, $reqVer, '<')) {
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

81
            if (version_compare($verNum, /** @scrutinizer ignore-type */ $reqVer, '<')) {
Loading history...
82
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
0 ignored issues
show
Bug introduced by
It seems like $reqVer can also be of type array; however, parameter $values of sprintf() does only seem to accept double|integer|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 ignore-type  annotation

82
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), /** @scrutinizer ignore-type */ $reqVer, $verNum));
Loading history...
83
                $success = false;
84
            }
85
        }
86
87
        return $success;
88
    }
89
}
90