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

action.module.php ➔ xoopspartnersCheckXoopsVer()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 33
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 10
nop 1
dl 0
loc 33
rs 6.7272
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 43 and the first side effect is on line 33.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
/**
13
 * XOOPS XoopsPartners module
14
 *
15
 * @package      module\xoopspartners\include
16
 * @author       Taiwen Jiang <[email protected]>
17
 * @author       zyspec <[email protected]>
18
 * @author       XOOPS Module Development Team
19
 * @copyright    {@link https://xoops.org 2001-2016 XOOPS Project}
20
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
21
 * @link         https://xoops.org XOOPS
22
 */
23
24
/**
25
 * @internal {Make sure you PROTECT THIS FILE}
26
 */
27
28
if ((!defined('XOOPS_ROOT_PATH'))
29
    || !isset($GLOBALS['xoopsUser'])
30
    || !($GLOBALS['xoopsUser'] instanceof XoopsUser)
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
    || !$GLOBALS['xoopsUser']->isAdmin()
32
) {
33
    exit('Restricted access' . PHP_EOL);
34
}
35
36
/**
37
 *
38
 * Prepares system prior to attempting to install module
39
 * @param XoopsModule $module {@link XoopsModule}
0 ignored issues
show
Documentation introduced by
There is no parameter named $module. Did you maybe mean $xoopsModule?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
40
 *
41
 * @return bool true if ready to install, false if not
42
 */
43 View Code Duplication
function xoops_module_pre_install_xoopspartners(XoopsModule $xoopsModule)
0 ignored issues
show
Duplication introduced by
This function 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...
44
{
45
    if (!class_exists('XoopspartnersUtilities')) {
46
        xoops_load('utilities', 'xoopspartners');
47
    }
48
49
    //check for minimum XOOPS version
50
    if (!XoopspartnersUtilities::checkXoopsVer($xoopsModule)) {
51
        return false;
52
    }
53
    // check for minimum PHP version
54
    if (!XoopspartnersUtilities::checkPHPVer($xoopsModule)) {
55
        return false;
56
    }
57
58
    return true;
59
}
60
61
/**
62
 *
63
 * Performs tasks required during installation of the module
64
 * @param XoopsModule $module {@link XoopsModule}
65
 *
66
 * @return bool true if installation successful, false if not
67
 */
68
function xoops_module_install_xoopspartners(XoopsModule $module)
0 ignored issues
show
Coding Style introduced by
xoops_module_install_xoopspartners uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
69
{
70
71
    $indexFile = $GLOBALS['xoops']->path('/modules/' . $module->dirname() . '/include/index.html');
72
73
    //Create the "uploads" directory for the module
74
    $module_uploads = $GLOBALS['xoops']->path('/uploads/' . $module->dirname());
75
    if (!is_dir($module_uploads)) {
76
        mkdir($module_uploads, 0777);
77
    }
78
    chmod($module_uploads, 0777);
79
    //now copy the index file to help prevent 'browsing' the directory
80
    copy($indexFile, $GLOBALS['xoops']->path('/uploads/' . $module->dirname() . '/index.html'));
81
82
    return true;
83
}
84
85
/**
86
 *
87
 * Prepares system prior to attempting to update module
88
 * @param XoopsModule $module {@link XoopsModule}
89
 *
90
 * @return bool true if successfully ready to update module, false if not
91
 */
92 View Code Duplication
function xoops_module_pre_update_xoopspartners(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function 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...
93
{
94
    if (!class_exists('XoopspartnersUtilities')) {
95
        xoops_load('utilities', 'xoopspartners');
96
    }
97
98
    //check for minimum XOOPS version
99
    if (!XoopspartnersUtilities::checkXoopsVer($xoopsModule)) {
100
        return false;
101
    }
102
    // check for minimum PHP version
103
    if (!XoopspartnersUtilities::checkPHPVer($xoopsModule)) {
104
        return false;
105
    }
106
107
    return true;
108
}
109
110
/**
111
 *
112
 * Functions to upgrade from previous version of the module
113
 *
114
 * @param XoopsModule $module       {@link XoopsModule}
115
 * @param int         $curr_version version number of module currently installed
0 ignored issues
show
Documentation introduced by
Should the type for parameter $curr_version not be integer|null?

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...
116
 *
117
 * @return bool true if successfully updated module, false if not
118
 */
119
function xoops_module_update_xoopspartners(XoopsModule $module, $curr_version = null)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $curr_version is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120
{
121
    return true;
122
}
123
124
/**
125
 *
126
 * Function to perform before module uninstall
127
 * @param XoopsModule $module {@link XoopsModule}
128
 *
129
 * @return bool true if successfully executed, false if not
130
 */
131
function xoops_module_pre_uninstall_xoopspartners(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
132
{
133
    return true;
134
}
135
136
/**
137
 *
138
 * Function to complete upon module uninstall
139
 * @param XoopsModule $module {@link XoopsModule}
140
 *
141
 * @return bool true if successfully executed uninstall of module, false if not
142
 */
143
function xoops_module_uninstall_xoopspartners(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
144
{
145
    return true;
146
}
147