Passed
Push — master ( d2520f...3f8ec2 )
by Michael
02:50
created

VersionChecks::checkVerXoops()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 12
nc 8
nop 2
1
<?php namespace XoopsModules\Extcal\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
 * @copyright   XOOPS Project (https://xoops.org)
15
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @author      mamba <[email protected]>
17
 */
18
19
20
21
trait VersionChecks
22
{
23
    /**
24
     *
25
     * Verifies XOOPS version meets minimum requirements for this module
26
     * @static
27
     * @param \XoopsModule $module
28
     *
29
     * @param null|string  $requiredVer
30
     * @return bool true if meets requirements, false if not
31
     */
32
    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null)
33
    {
34
        $moduleDirName = basename(dirname(dirname(__DIR__)));
35
        if (null === $module) {
36
            $module = \XoopsModule::getByDirname($moduleDirName);
37
        }
38
        xoops_loadLanguage('admin', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

38
        /** @scrutinizer ignore-call */ 
39
        xoops_loadLanguage('admin', $moduleDirName);
Loading history...
39
40
        //check for minimum XOOPS version
41
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extcal\Common\XOOPS_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
42
        if (null === $requiredVer) {
43
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
44
        }
45
        $success = true;
46
47
        if (version_compare($currentVer, $requiredVer, '<')) {
48
            $success = false;
49
            $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper does not exist. Did you maybe mean $module?
Loading history...
50
        }
51
52
        return $success;
53
    }
54
55
    /**
56
     *
57
     * Verifies PHP version meets minimum requirements for this module
58
     * @static
59
     * @param \XoopsModule $module
60
     *
61
     * @return bool true if meets requirements, false if not
62
     */
63
    public static function checkVerPhp(\XoopsModule $module)
64
    {
65
        $moduleDirName = basename(dirname(dirname(__DIR__)));
66
        xoops_loadLanguage('admin', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

66
        /** @scrutinizer ignore-call */ 
67
        xoops_loadLanguage('admin', $moduleDirName);
Loading history...
67
        // check for minimum PHP version
68
        $success = true;
69
        $verNum  = PHP_VERSION;
70
        $reqVer  = $module->getInfo('min_php');
71
        if (false !== $reqVer && '' !== $reqVer) {
72
            if (version_compare($verNum, $reqVer, '<')) {
73
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper does not exist. Did you maybe mean $module?
Loading history...
74
                $success = false;
75
            }
76
        }
77
78
        return $success;
79
    }
80
}
81