Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

VersionChecks::checkVerXoops()   D

Complexity

Conditions 9
Paths 40

Size

Total Lines 39
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 27
nc 40
nop 2
dl 0
loc 39
rs 4.909
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright   XOOPS Project (https://xoops.org)
14
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @author      mamba <[email protected]>
16
 */
17
trait VersionChecks
0 ignored issues
show
Coding Style Compatibility introduced by
Each trait must be in a namespace of at least one level (a top-level vendor name)

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
18
{
19
    /**
20
     *
21
     * Verifies XOOPS version meets minimum requirements for this module
22
     * @static
23
     * @param XoopsModule $module
0 ignored issues
show
Documentation introduced by
Should the type for parameter $module not be null|XoopsModule?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
24
     *
25
     * @param null|string $requiredVer
26
     * @return bool true if meets requirements, false if not
27
     */
28
    public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
29
    {
30
        $moduleDirName = basename(dirname(__DIR__));
31
        if (null === $module) {
32
            $module = XoopsModule::getByDirname($moduleDirName);
33
        }
34
        xoops_loadLanguage('admin', $moduleDirName);
35
        //check for minimum XOOPS version
36
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
37
        $currArray  = explode('.', $currentVer);
38
        if (null === $requiredVer) {
39
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
40
        }
41
        $reqArray = explode('.', $requiredVer);
42
        $success  = true;
43
        foreach ($reqArray as $k => $v) {
44
            if (isset($currArray[$k])) {
45
                if ($currArray[$k] > $v) {
46
                    break;
47
                } elseif ($currArray[$k] == $v) {
48
                    continue;
49
                } else {
50
                    $success = false;
51
                    break;
52
                }
53
            } else {
54
                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
55
                    $success = false;
56
                    break;
57
                }
58
            }
59
        }
60
61
        if (false === $success) {
62
            $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
63
        }
64
65
        return $success;
66
    }
67
68
    /**
69
     *
70
     * Verifies PHP version meets minimum requirements for this module
71
     * @static
72
     * @param XoopsModule $module
73
     *
74
     * @return bool true if meets requirements, false if not
75
     */
76
    public static function checkVerPhp(XoopsModule $module)
77
    {
78
        xoops_loadLanguage('admin', $module->dirname());
79
        // check for minimum PHP version
80
        $success = true;
81
        $verNum  = PHP_VERSION;
82
        $reqVer  = $module->getInfo('min_php');
83
        if (false !== $reqVer && '' !== $reqVer) {
84
            if (version_compare($verNum, $reqVer, '<')) {
85
                $module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum));
86
                $success = false;
87
            }
88
        }
89
90
        return $success;
91
    }
92
}
93