Completed
Pull Request — master (#13)
by
unknown
01:57
created

TagUtilities::checkPHPVer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 6
Ratio 40 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 6
loc 15
rs 9.4285
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
 * Module: Tag
13
 *
14
 * @category        Module
15
 * @package         Tag
16
 * @author          XOOPS Module Development Team
17
 * @author          Mamba
18
 * @copyright       {@link http://xoops.org The XOOPS Project}
19
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
20
 * @link            http://xoops.org XOOPS
21
 * @since           2.00
22
 */
23
24
/**
25
 * TagUtilities
26
 *
27
 * Static utilities class to provide common functionality
28
 *
29
 */
30
class TagUtilities
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

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...
31
{
32
    /**
33
     *
34
     * Verifies XOOPS version meets minimum requirements for this module
35
     * @static
36
     * @param XoopsModule $module
37
     *
38
     * @return bool true if meets requirements, false if not
39
     */
40 View Code Duplication
    public static function checkXoopsVer(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
41
    {
42
        xoops_loadLanguage('admin', $module->dirname());
43
        //check for minimum XOOPS version
44
        $currentVer  = substr(XOOPS_VERSION, 6); // get the numeric part of string
45
        $currArray   = explode('.', $currentVer);
46
        $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
47
        $reqArray    = explode('.', $requiredVer);
48
        $success     = true;
49
        foreach ($reqArray as $k => $v) {
50
            if (isset($currArray[$k])) {
51
                if ($currArray[$k] > $v) {
52
                    break;
53
                } elseif ($currArray[$k] == $v) {
54
                    continue;
55
                } else {
56
                    $success = false;
57
                    break;
58
                }
59
            } else {
60
                if ((int)$v > 0) { // handles things like x.x.x.0_RC2
61
                    $success = false;
62
                    break;
63
                }
64
            }
65
        }
66
67
        if (!$success) {
68
            $module->setErrors(sprintf(_AM_TAG_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
69
        }
70
71
        return $success;
72
    }
73
74
    /**
75
     *
76
     * Verifies PHP version meets minimum requirements for this module
77
     * @static
78
     * @param XoopsModule $module
79
     *
80
     * @return bool true if meets requirements, false if not
81
     */
82
    public static function checkPHPVer(XoopsModule $module)
83
    {
84
        xoops_loadLanguage('admin', $module->dirname());
85
        // check for minimum PHP version
86
        $success = true;
87
        $verNum  = phpversion();
88
        $reqVer  =& $module->getInfo('min_php');
89 View Code Duplication
        if (isset($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...
90
            if (version_compare($verNum, $reqVer, '<')) {
91
                $module->setErrors(sprintf(_AM_TAG_ERROR_BAD_PHP, $reqVer, $verNum));
92
                $success = false;
93
            }
94
        }
95
        return $success;
96
    }
97
}
98