xhp_block_completed.php ➔ b_XHP_completed_show()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 19

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 1
dl 23
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
// $Id: xhp_block_completed.php 11919 2013-08-14 14:07:10Z beckmi $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.xoops.org/>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
// Variables
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
29
// $options[0]: sorting order <DESC or ''> //
30
// $options[1]: num to list //
31
// $options[2]: min num to list //
32
// $options[3]: module dirname //
33
34
/**
35
 * @param $options
36
 * @return array
37
 */
38 View Code Duplication
function b_XHP_completed_show($options)
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...
39
{
40
    global $xoopsDB, $xoopsUser, $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
41
    $myts      = MyTextSanitizer::getInstance();
42
    $block     = array();
43
    $mydirname = $options[3];
44
    $mymodpath = "modules/$mydirname";
45
    include "$mymodpath/module_prefix.php";
46
    $rsl    = $xoopsDB->prefix($module_prefix . '_results');
0 ignored issues
show
Bug introduced by
The variable $module_prefix does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
47
    $usr    = $xoopsDB->prefix('users');
48
    $sql    =
49
        "SELECT count(*) AS completed, $rsl.uid, $usr.uname FROM $rsl INNER JOIN $usr ON $rsl.uid=$usr.uid GROUP BY $rsl.uid HAVING completed >= $options[2] ORDER BY completed $options[0] LIMIT $options[1]";
50
    $result = $xoopsDB->query($sql);
51
    while ($myrow = $xoopsDB->fetchArray($result)) {
52
        $items              = array();
53
        $items['completed'] = $myrow['completed'];
54
        $items['uname']     = $myrow['uname'];
55
        $items['uid']       = $myrow['uid'];
56
        $block['items'][]   = $items;
57
    }
58
59
    return $block;
60
}
61
62
/**
63
 * @param $options
64
 * @return string
65
 */
66 View Code Duplication
function b_XHP_completed_edit($options)
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...
67
{
68
    $form = _MB_XHP_ITEMS_ORDER . "&nbsp;<select name='options[]'>";
69
    $form .= "<option value='DESC'";
70
    if ($options[0] === 'DESC') {
71
        $form .= " selected='selected'";
72
    }
73
    $form .= '>' . _MB_XHP_ITEMS_DESC . "</option>\n";
74
    $form .= "<option value=''";
75
    if ($options[0] === '') {
76
        $form .= " selected='selected'";
77
    }
78
    $form .= '>' . _MB_XHP_ITEMS_ASCEND . "</option>\n";
79
    $form .= "</select>\n";
80
    $form .= '&nbsp;' . _MB_XHP_ITEMS_DISP . "&nbsp;<input type='text'  size=5 name='options[]' value='" . $options[1] . "' />&nbsp;" . _MB_XHP_ITEMS_ARTCLS . "<br>\n";
81
    $form .= '&nbsp;' . _MB_XHP_MINIMUM . "&nbsp;<input type='text'  size=5 name='options[]' value='" . $options[2] . "' />&nbsp; " . _MB_XHP_ITEMS_ARTCLS;
82
    $form .= "<input type='hidden' name='options[]' value='" . $options[3] . "'>";
83
84
    return $form;
85
}
86