Completed
Push — master ( e6990f...463166 )
by Michael
05:51 queued 03:04
created

onupdate.php ➔ tableExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 9.4285
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 37 and the first side effect is on line 29.

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 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
/**
14
 * Module: Tag
15
 *
16
 * @category        Module
17
 * @package         tag
18
 * @author          XOOPS Module Development Team
19
 * @author          Mamba
20
 * @author          Herve Thouzard
21
 * @copyright       {@link http://xoops.org 2001-2016 XOOPS Project}
22
 * @coypright       Herve Thouzard
23
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
24
 * @link            http://xoops.org XOOPS
25
 * @since           2.00
26
 */
27
28
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->IsAdmin()) {
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...
29
    exit('Restricted access' . PHP_EOL);
30
}
31
32
/**
33
 * @param string $tablename
34
 *
35
 * @return bool
36
 */
37
function tableExists($tablename)
0 ignored issues
show
Coding Style introduced by
tableExists 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...
38
{
39
    $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
40
    return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false;
41
}
42
43
/**
44
 *
45
 * Prepares system prior to attempting to install module
46
 * @param XoopsModule $module {@link XoopsModule}
47
 *
48
 * @return bool true if ready to install, false if not
49
 */
50
function xoops_module_pre_update_tag(XoopsModule $module)
0 ignored issues
show
Best Practice introduced by
The function xoops_module_pre_update_tag() has been defined more than once; this definition is ignored, only the first definition in include/action.module.php (L87-90) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
51
{
52
53
    if (!class_exists('TagUtilities')) {
54
        xoops_load('utilities', 'tag');
55
    }
56
    //check for minimum XOOPS version
57
    if (!TagUtilities::checkXoopsVer($module)) {
58
        return false;
59
    }
60
61
    // check for minimum PHP version
62
    if (!TagUtilities::checkPHPVer($module)) {
63
        return false;
64
    }
65
    return true;
66
}
67
68
/**
69
 *
70
 * Performs tasks required during update of the module
71
 * @param XoopsModule $module {@link XoopsModule}
72
 * @param  null       $prev_version
73
 *
74
 * @return bool true if update successful, false if not
75
 */
76
77 View Code Duplication
function xoops_module_update_tag(XoopsModule $module, $prev_version = null)
0 ignored issues
show
Best Practice introduced by
The function xoops_module_update_tag() has been defined more than once; this definition is ignored, only the first definition in include/action.module.php (L106-120) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

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...
Coding Style introduced by
xoops_module_update_tag 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...
78
{
79
    //load_functions("config");
80
    //mod_clearConfg($module->getVar("dirname", "n"));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
82
    if ($prev_version <= 150) {
83
        $GLOBALS['xoopsDB']->queryFromFile($GLOBALS['xoops']->path('/modules/' . $module->getVar('dirname') . '/sql/mysql.150.sql'));
84
    }
85
86
    /* Do some synchronization */
87
    include_once $GLOBALS['xoops']->path('/modules/' . $module->getVar('dirname') . '/include/functions.recon.php');
88
    tag_synchronization();
89
90
    return true;
91
}
92