Completed
Branch master (171474)
by Michael
02:13 queued 55s
created

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