Completed
Push — master ( a1059e...55b12e )
by Michael
01:29
created

VersionChecks   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B checkVerXoops() 0 22 4
A checkVerPhp() 0 16 4
1
<?php namespace XoopsModules\Marquee\Common;
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright   XOOPS Project (https://xoops.org)
15
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @author      mamba <[email protected]>
17
 */
18
trait VersionChecks
19
{
20
    /**
21
     *
22
     * Verifies XOOPS version meets minimum requirements for this module
23
     * @static
24
     * @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...
25
     *
26
     * @param null|string $requiredVer
27
     * @return bool true if meets requirements, false if not
28
     */
29
    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null)
30
    {
31
        $moduleDirName = basename(dirname(dirname(__DIR__)));
32
        if (null === $module) {
33
            $module = \XoopsModule::getByDirname($moduleDirName);
34
        }
35
        xoops_loadLanguage('admin', $moduleDirName);
36
37
        //check for minimum XOOPS version
38
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
39
        if (null === $requiredVer) {
40
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
41
        }
42
        $success     = true;
43
44
        if (version_compare($currentVer, $requiredVer, '<')){
45
            $success     = false;
46
            $module->setErrors(sprintf(_AM_MARQUEE_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
47
        }
48
49
        return $success;
50
    }
51
52
    /**
53
     *
54
     * Verifies PHP version meets minimum requirements for this module
55
     * @static
56
     * @param \XoopsModule $module
57
     *
58
     * @return bool true if meets requirements, false if not
59
     */
60
    public static function checkVerPhp(\XoopsModule $module)
61
    {
62
        xoops_loadLanguage('admin', $module->dirname());
63
        // check for minimum PHP version
64
        $success = true;
65
        $verNum  = PHP_VERSION;
66
        $reqVer  = $module->getInfo('min_php');
67
        if (false !== $reqVer && '' !== $reqVer) {
68
            if (version_compare($verNum, $reqVer, '<')) {
69
                $module->setErrors(sprintf(_AM_MARQUEE_ERROR_BAD_PHP, $reqVer, $verNum));
70
                $success = false;
71
            }
72
        }
73
74
        return $success;
75
    }
76
}
77