Completed
Push — master ( 625b06...275716 )
by Michael
02:45
created

search.inc.php ➔ smallworld_search()   D

Complexity

Conditions 13
Paths 192

Size

Total Lines 78
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 57
nc 192
nop 6
dl 0
loc 78
rs 4.8045
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 24 and the first side effect is on line 21.

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
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
*
10
* @copyright:			The XOOPS Project http://sourceforge.net/projects/xoops/
11
* @license:				http://www.fsf.org/copyleft/gpl.html GNU public license
12
* @module:				Smallworld
13
* @Author:				Michael Albertsen (http://culex.dk) <[email protected]>
14
* @copyright:			2011 Culex
15
* @Repository path:		$HeadURL: https://xoops.svn.sourceforge.net/svnroot/xoops/XoopsModules/smallworld/trunk/smallworld/permalink.php $
16
* @Last committed:		$Revision: 8924 $
17
* @Last changed by:		$Author: djculex $
18
* @Last changed date:	$Date: 2012-02-09 21:13:23 +0100 (to, 09 feb 2012) $
19
* @ID:					$Id: permalink.php 8924 2012-02-09 20:13:23Z djculex $
20
**/
21
include_once(XOOPS_ROOT_PATH."/modules/smallworld/class/class_collector.php");
22
include_once XOOPS_ROOT_PATH.'/modules/smallworld/include/functions.php';
23
24
function smallworld_search($queryarray, $andor, $limit, $offset, $userid, $sortby = "created DESC")
25
{
26
    global $xoopsDB, $xoopsConfig, $myts, $xoopsUser;
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...
27
    
28
    if (file_exists(XOOPS_ROOT_PATH.'/modules/smallworld/language/'.$xoopsConfig['language'].'/main.php')) {
29
        require_once (XOOPS_ROOT_PATH.'/modules/smallworld/language/'.$xoopsConfig['language'].'/main.php');
30
    } else {
31
        require_once (XOOPS_ROOT_PATH.'/modules/smallworld/language/english/main.php');
32
    }
33
          
34
    $module_handler =& xoops_gethandler('module');
35
    $module =& $module_handler->getByDirname('smallworld');
36
    $modid= $module->getVar('mid');
0 ignored issues
show
Unused Code introduced by
$modid 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...
37
    $searchparam='';
0 ignored issues
show
Unused Code introduced by
$searchparam 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...
38
    $highlight = false;
39
    
40
    $gperm_handler =& xoops_gethandler('groupperm');
41
    if (is_object($xoopsUser)) {
42
        $groups = $xoopsUser->getGroups();
0 ignored issues
show
Unused Code introduced by
$groups 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...
43
        $id = $xoopsUser->getVar('uid');
44
        $Wall = new Wall_Updates();
45
        $followers = Smallworld_array_flatten($Wall->getFollowers($id),0);
46
    } else {
47
        $id = 0;
48
        $groups = XOOPS_GROUP_ANONYMOUS;
0 ignored issues
show
Unused Code introduced by
$groups 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...
49
        $followers = array();
50
    }
51
    
52
    if ($id > 0 && $id != '') {
53
    
54
        $sql = "SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM "
55
            . $xoopsDB->prefix('smallworld_messages')." M, ".$xoopsDB->prefix('smallworld_user')
56
            . " U WHERE M.uid_fk=U.userid";
57
    } else {
58
        $sql = "SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM "
59
            . $xoopsDB->prefix('smallworld_messages')." M, ".$xoopsDB->prefix('smallworld_user')
60
            . " U WHERE M.uid_fk=U.userid";
61
    }
62
        
63
        
64
        
65
    if ( $userid != 0 ) {
66
        $sql .= " AND M.uid_fk = ".$userid." ";
67
    }
68
    if ( is_array($queryarray) && $count = count($queryarray) ) {
69
        $sql .= " AND (M.message LIKE '%$queryarray[0]%' OR M.message LIKE '%$queryarray[0]%' OR U.username LIKE '%$queryarray[0]%'";
70
        $sql .= ") ";
71
        // keywords highlighting
72
        if($highlight) {
73
            $searchparam='&keywords='.urlencode(trim(implode(' ',$queryarray)));
0 ignored issues
show
Unused Code introduced by
$searchparam 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...
74
        }
75
    }
76
    $sql .= "ORDER BY created DESC";
77
    $result = $xoopsDB->query($sql,$limit,$offset);
78
    $ret = array();
79
    $i = 0;
80
    while($myrow = $xoopsDB->fetchArray($result)){
81
        if (in_array($myrow['uid_fk'], $followers) || $myrow['uid_fk'] == $id) {
82
            $ret[$i]['image'] = "images/smallworld_icn.png";
83
            $ret[$i]['link'] = "permalink.php?ownerid=".$myrow['uid_fk']."&updid=".$myrow['msg_id'];
84
            if(preg_match('/UPLIMAGE/',$myrow['message'])) {
85
                $ownmsg = str_replace("UPLIMAGE ", "", $myrow['message']);
86
                $ret[$i]['title'] = $ownmsg;
87
                $ret[$i]['title'] = Smallworld_getName($myrow['uid_fk'])." -> "._SMALLWORLD_GALLERY;
88
                $ret[$i]['title'] = str_replace(array('&lt;','&gt;'),array('<','>'), $ret[$i]['title']);
89
            } else {
90
                $ret[$i]['title'] = smallworld_shortenText($myrow['message'], 60);
91
            }
92
            $ret[$i]['time'] = $myrow['created'];
93
            $ret[$i]['uid'] = $myrow['uid_fk'];
94
        } else {
95
            $i = $i-1;
96
        }
97
            $i++;
98
    }
99
100
    return $ret;
101
}
102