Completed
Push — master ( 484dcf...d1b073 )
by Michael
14s
created

XoopspartnersUtilities   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C checkXoopsVer() 0 32 7
A checkPHPVer() 0 15 4
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits of
4
 supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit
6
 authors.
7
8
 This program is distributed in the hope that it will be useful, but
9
 WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * Module: Partners
14
 *
15
 * @package         module\xoopspartners\class
16
 * @author          XOOPS Module Development Team
17
 * @author          Mamba, ZySpec
18
 * @copyright       http://xoops.org 2001-2016 XOOPS Project
19
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @since           1.13
21
 */
22
23
 /**
24
  * XoopspartnersUtilities
25
  *
26
  * Static utilities class to provide common functionality
27
  *
28
  */
29
class XoopspartnersUtilities
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...
30
{
31
    /**
32
     * Verifies XOOPS version meets minimum requirements for this module
33
     *
34
     * @static
35
     * @param XoopsModule
36
     *
37
     * @return bool true if meets requirements, false if not
38
     */
39
    public static function checkXoopsVer(&$module) {
40
        xoops_loadLanguage('admin', $module->dirname());
41
        //check for minimum XOOPS version
42
        $currentVer  = substr(XOOPS_VERSION, 6); // get the numeric part of string
43
        $currArray   = explode('.', $currentVer);
44
        $requiredVer = "" . $module->getInfo('min_xoops'); //making sure it's a string
45
        $reqArray    = explode('.', $requiredVer);
46
        $success     = true;
47
        foreach ($reqArray as $k=>$v) {
48
            if (isset($currArray[$k])) {
49
                if ($currArray[$k] > $v) {
50
                    break;
51
                } elseif ($currArray[$k] == $v ) {
52
                    continue;
53
                } else {
54
                    $success = false;
55
                    break;
56
                }
57
            } else {
58
                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
59
                    $success = false;
60
                    break;
61
                }
62
            }
63
        }
64
65
        if (!$success) {
66
            $module->setErrors(sprintf(_AM_XOOPSPARTNERS_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
67
        }
68
69
        return $success;
70
    }
71
    /**
72
     * Verifies PHP version meets minimum requirements for this module
73
     *
74
     * @static
75
     * @param XoopsModule
76
     *
77
     * @return bool true if meets requirements, false if not
78
     */
79
    public static function checkPHPVer(&$module)
80
    {
81
        xoops_loadLanguage('admin', $module->dirname());
82
        // check for minimum PHP version
83
        $success = true;
84
        $verNum  = phpversion();
85
        $reqVer  = $module->getInfo('min_php');
86
        if ((false !== $reqVer) && ('' !== $reqVer)) {
87
            if (version_compare($verNum, (string)$reqVer, '<')) {
88
                $module->setErrors(sprintf(_AM_XOOPSPARTNERS_ERROR_BAD_PHP, $reqVer, $verNum));
89
                $success = false;
90
            }
91
        }
92
        return $success;
93
    }
94
}
95