Completed
Push — master ( 3f2fe9...f5ab6b )
by Michael
01:21
created

RandomquoteUtility   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
C checkXoopsVer() 0 33 7
A checkPHPVer() 0 15 3
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: RandomQuote
13
 *
14
 * @category        Module
15
 * @package         randomquote
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
 * RandomquoteUtility
26
 *
27
 * Static utility class to provide common functionality
28
 *
29
 */
30
class RandomquoteUtility
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
37
     *
38
     * @return bool true if meets requirements, false if not
39
     */
40
    public static function checkXoopsVer(&$module)
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_RANDOMQUOTE_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
79
     *
80
     * @return bool true if meets requirements, false if not
81
     */
82
    public static function checkPHPVer(&$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
        if (isset($reqVer)) {
90
            if (version_compare($verNum, $reqVer, '<')) {
91
                $module->setErrors(sprintf(_AM_RANDOMQUOTE_ERROR_BAD_PHP, $reqVer, $verNum));
92
                $success = false;
93
            }
94
        }
95
        return $success;
96
    }
97
}
98