Completed
Push — master ( 10bab4...a0a78b )
by Michael
02:06
created

VersionChecks::checkVerXoops()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 13

Duplication

Lines 4
Ratio 18.18 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 8
nop 2
dl 4
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php namespace XoopsModules\Planet\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
trait VersionChecks
19
{
20
    /**
21
     *
22
     * Verifies XOOPS version meets minimum requirements for this module
23
     * @static
24
     * @param \XoopsModule $module
25
     *
26
     * @param null|string $requiredVer
27
     * @return bool true if meets requirements, false if not
28
     */
29
    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null)
30
    {
31
        $moduleDirName = basename(dirname(dirname(__DIR__)));
32
        if (null === $module) {
33
            $module = \XoopsModule::getByDirname($moduleDirName);
34
        }
35
        xoops_loadLanguage('admin', $moduleDirName);
36
37
        //check for minimum XOOPS version
38
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
39
        if (null === $requiredVer) {
40
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
41
        }
42
        $success     = true;
43
44 View Code Duplication
        if (version_compare($currentVer, $requiredVer, '<')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
            $success     = false;
46
            $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
0 ignored issues
show
Bug introduced by
The variable $moduleDirNameUpper does not exist. Did you mean $module?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
47
        }
48
49
        return $success;
50
    }
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
        xoops_loadLanguage('admin', $module->dirname());
63
        // check for minimum PHP version
64
        $success = true;
65
        $verNum  = PHP_VERSION;
66
        $reqVer  = $module->getInfo('min_php');
67
        if (false !== $reqVer && '' !== $reqVer) {
68 View Code Duplication
            if (version_compare($verNum, $reqVer, '<')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
0 ignored issues
show
Bug introduced by
The variable $moduleDirNameUpper does not exist. Did you mean $module?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
70
                $success = false;
71
            }
72
        }
73
74
        return $success;
75
    }
76
}
77