Completed
Branch master (ddc2b8)
by Michael
02:46
created

xoopstube_banner.php ➔ xtubeEditBannerB()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
    /** @var XoopsModuleHandler $moduleHandler */
31
    $moduleHandler         = xoops_getHandler('module');
32
    $xoopstubeModule       = $moduleHandler->getByDirname($moduleDirName);
33
    $configHandler         = xoops_getHandler('config');
34
    $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...
35
36
    $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 '
37
                                         . $GLOBALS['xoopsDB']->prefix('xoopstube_cat')
38
                                         . ' a, '
39
                                         . $GLOBALS['xoopsDB']->prefix('banner')
40
                                         . ' b WHERE (b.cid = a.client_id) OR (b.bid = a.banner_id) ORDER BY b.cid, b.bid, a.title ASC');
41
42
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
43
        $impmade    = $myrow['impmade'];
44
        $clicks     = $myrow['clicks'];
45
        $imptotal   = $myrow['imptotal'];
46
        $bannerload = array();
47
        $result2    = $GLOBALS['xoopsDB']->query('SELECT name FROM ' . $GLOBALS['xoopsDB']->prefix('bannerclient') . ' WHERE cid=' . (int)$myrow['cid']);
48
        $myclient   = $GLOBALS['xoopsDB']->fetchArray($result2);
49
        if ($impmade == 0) {
50
            $percent = 0;
51
        } else {
52
            $percent = substr(100 * $clicks / $impmade, 0, 5);
53
        }
54
        if ($imptotal == 0) {
55
            $left = 'Unlimited';
56
        } else {
57
            $left = (int)$imptotal - (int)$impmade;
58
        }
59
        $bannerload['cat']      = (int)$myrow['acid'];
60
        $bannerload['bid']      = (int)$myrow['bid'];
61
        $bannerload['cid']      = (int)$myrow['cid'];
62
        $bannerload['imptotal'] = (int)$myrow['imptotal'];
63
        $bannerload['impmade']  = (int)$myrow['impmade'];
64
        $bannerload['impleft']  = $left;
65
        $bannerload['clicks']   = (int)$myrow['clicks'];
66
        $bannerload['client']   = $myclient['name'];
67
        $bannerload['percent']  = $percent;
68
        $bannerload['cattitle'] = $myrow['title'];
69
        $bannerload['dirname']  = $xoopstubeModule->getVar('dirname');
70
        $block['banners'][]     = $bannerload;
71
    }
72
    unset($_block_check_array);
73
74
    return $block;
75
}
76
77
/**
78
 * @param $options
79
 *
80
 * @return string
81
 */
82
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...
83
{
84
    $form = '';
85
86
    return $form;
87
}
88