Completed
Push — master ( 3024c9...954431 )
by Michael
04:21
created

xoopstube_banner.php ➔ xtubeShowBannerB()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 48
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 39
c 2
b 0
f 0
nc 5
nop 1
dl 0
loc 48
rs 8.7396
1
<?php
2
/**
3
 * XoopsTube - a multicategory video management module
4
 *
5
 * Based upon WF-Links
6
 *
7
 * File: blocks/xoopstube_banner.php
8
 *
9
 * @copyright        http://xoops.org/ XOOPS Project
10
 * @copyright        XOOPS_copyrights.txt
11
 * @copyright        http://www.impresscms.org/ The ImpressCMS Project
12
 * @license          GNU General Public License (GPL)
13
 *                   a copy of the GNU license is enclosed.
14
 * ----------------------------------------------------------------------------------------------------------
15
 * @package          XoopsTube
16
 * @since            1.00
17
 * @author           McDonald
18
 *
19
 * @param $options
20
 *
21
 * @return array
22
 */
23
24
function xtubeShowBannerB($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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...
Coding Style introduced by
xtubeShowBannerB 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...
25
{
26
    $moduleDirName = basename(dirname(__DIR__));
27
28
    $block                 = array();
29
    $time                  = time();
0 ignored issues
show
Unused Code introduced by
$time is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
    $moduleHandler         = xoops_getHandler('module');
31
    $xoopstubeModule       = $moduleHandler->getByDirname($moduleDirName);
32
    $configHandler         = xoops_getHandler('config');
33
    $xoopstubeModuleConfig = $configHandler->getConfigsByCat(0, $xoopstubeModule->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
$xoopstubeModuleConfig is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
35
    $result = $GLOBALS['xoopsDB']->query('SELECT a.cid as acid, a.title, a.client_id, a.banner_id, b.bid, b.cid, b.imptotal, b.impmade, b.clicks FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat')
36
                                         . ' a, ' . $GLOBALS['xoopsDB']->prefix('banner') . ' b WHERE (b.cid = a.client_id) OR (b.bid = a.banner_id) ORDER BY b.cid, b.bid, a.title ASC');
37
38
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
39
        $impmade    = $myrow['impmade'];
40
        $clicks     = $myrow['clicks'];
41
        $imptotal   = $myrow['imptotal'];
42
        $bannerload = array();
43
        $result2    = $GLOBALS['xoopsDB']->query('SELECT name FROM ' . $GLOBALS['xoopsDB']->prefix('bannerclient') . ' WHERE cid=' . (int)$myrow['cid']);
44
        $myclient   = $GLOBALS['xoopsDB']->fetchArray($result2);
45
        if ($impmade == 0) {
46
            $percent = 0;
47
        } else {
48
            $percent = substr(100 * $clicks / $impmade, 0, 5);
49
        }
50
        if ($imptotal == 0) {
51
            $left = 'Unlimited';
52
        } else {
53
            $left = (int)$imptotal - (int)$impmade;
54
        }
55
        $bannerload['cat']      = (int)$myrow['acid'];
56
        $bannerload['bid']      = (int)$myrow['bid'];
57
        $bannerload['cid']      = (int)$myrow['cid'];
58
        $bannerload['imptotal'] = (int)$myrow['imptotal'];
59
        $bannerload['impmade']  = (int)$myrow['impmade'];
60
        $bannerload['impleft']  = $left;
61
        $bannerload['clicks']   = (int)$myrow['clicks'];
62
        $bannerload['client']   = $myclient['name'];
63
        $bannerload['percent']  = $percent;
64
        $bannerload['cattitle'] = $myrow['title'];
65
        $bannerload['dirname']  = $xoopstubeModule->getVar('dirname');
66
        $block['banners'][]     = $bannerload;
67
    }
68
    unset($_block_check_array);
69
70
    return $block;
71
}
72
73
/**
74
 * @param $options
75
 *
76
 * @return string
77
 */
78
function xtubeEditBannerB($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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...
79
{
80
    $form = '';
81
82
    return $form;
83
}
84