VersionChecks::checkVerPhp()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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

47
            $requiredVer = '' . /** @scrutinizer ignore-type */ $module->getInfo('min_xoops'); //making sure it's a string
Loading history...
48
        }
49
        $success = true;
50
51
        if (version_compare($currentVer, $requiredVer, '<')) {
52
            $success = false;
53
            $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
54
        }
55
56
        return $success;
57
    }
58
59
    /**
60
     *
61
     * Verifies PHP version meets minimum requirements for this module
62
     * @static
63
     * @param \XoopsModule $module
64
     *
65
     * @return bool true if meets requirements, false if not
66
     */
67
    public static function checkVerPhp(\XoopsModule $module)
68
    {
69
        $moduleDirName      = basename(dirname(dirname(__DIR__)));
70
        $moduleDirNameUpper = strtoupper($moduleDirName);
71
        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

71
        xoops_loadLanguage('admin', /** @scrutinizer ignore-type */ $module->dirname());
Loading history...
72
        // check for minimum PHP version
73
        $success = true;
74
        $verNum  = PHP_VERSION;
75
        $reqVer  = $module->getInfo('min_php');
76
        if (false !== $reqVer && '' !== $reqVer) {
77
            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

77
            if (version_compare($verNum, /** @scrutinizer ignore-type */ $reqVer, '<')) {
Loading history...
78
                $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 $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 ignore-type  annotation

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