AlumniSearchPlugin   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C search() 0 64 8
1
<?php
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
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * alumni module
14
 * Edited by John Mordo (jlm69)
15
 * @copyright       XOOPS Project https://xoops.org/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @since           2.6.0
18
 * @author          Mage Grégory (AKA Mage)
19
 * @version         $Id: $
20
 */
21
22
use Xoops\Core\Request;
23
use Xoops\Module\Plugin\PluginAbstract;
24
use Xmf\Metagen;
25
26
/**
27
 * Class AlumniSearchPlugin
28
 */
29
class AlumniSearchPlugin extends PluginAbstract implements SearchPluginInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
{
31
    /**
32
     * @param string[] $queries
33
     * @param string   $andor
34
     * @param int      $limit
35
     * @param int      $start
36
     * @param \type    $userid
37
     * @return array
38
     */
39
    public function search($queries, $andor, $limit, $start, $userid)
40
    {
41
        $xoops   = Xoops::getInstance();
42
        $alumni  = Alumni::getInstance();
0 ignored issues
show
Unused Code introduced by
$alumni 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
        $myts    = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
44
        $by_cat  = Request::getInt('by_cat', '');
0 ignored issues
show
Coding Style introduced by
$by_cat does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
45
        $andor   = Request::getWord('andor', 'AND');
0 ignored issues
show
Unused Code introduced by
$andor 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...
46
        $queries = [];
0 ignored issues
show
Unused Code introduced by
$queries 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...
47
        $query   = Request::getString('query', '');
48
        $start   = Request::getInt('start', '0');
49
50
        $helper         = Xoops::getModuleHelper('alumni');
51
        $module_id      = $helper->getModule()->getVar('mid');
0 ignored issues
show
Coding Style introduced by
$module_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
52
        $listingHandler = $helper->getHandler('listing');
53
        $groups         = $xoops->getUserGroups();
54
        $alumni_ids     = $xoops->getHandlerGroupperm()->getItemIds('alumni_view', $groups, $module_id);
0 ignored issues
show
Coding Style introduced by
$alumni_ids does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
55
        $all_ids        = implode(', ', $alumni_ids);
0 ignored issues
show
Coding Style introduced by
$all_ids does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
56
57
        $criteria = new CriteriaCompo();
58
        $criteria->add(new Criteria('valid', 1, '='));
59
        //  $criteria->add(new Criteria('date', time(), '<='));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
60
        $criteria->add(new Criteria('cid', '(' . $all_ids . ')', 'IN'));
0 ignored issues
show
Coding Style introduced by
$all_ids does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
61
        if (0 != $userid) {
62
            $criteria->add(new Criteria('usid', $userid, '='));
63
        }
64
        if ($by_cat) {
0 ignored issues
show
Coding Style introduced by
$by_cat does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
65
            $criteria->add(new Criteria('cid', $by_cat, '='));
0 ignored issues
show
Coding Style introduced by
$by_cat does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
66
        }
67
68
        $queries = [$query];
69
        $queries = implode('+', $queries);
70
71
        $count = 0;
0 ignored issues
show
Unused Code introduced by
$count 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...
72
        $i     = 0;
0 ignored issues
show
Unused Code introduced by
$i 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...
73
74
        $criteria->add(new Criteria('name', '%' . $queries . '%', 'LIKE'), 'AND');
75
        $criteria->add(new Criteria('mname', '%' . $queries . '%', 'LIKE'), 'OR');
76
        $criteria->add(new Criteria('lname', '%' . $queries . '%', 'LIKE'), 'OR');
77
        $criteria->add(new Criteria('school', '%' . $queries . '%', 'LIKE'), 'OR');
78
        $criteria->add(new Criteria('year', '%' . $queries . '%', 'LIKE'), 'OR');
79
80
        $criteria->setLimit($limit);
81
        $criteria->setSort('date');
82
        $criteria->setOrder('DESC');
83
        $criteria->setStart($start);
84
85
        $numrows     = $listingHandler->getCount();
0 ignored issues
show
Unused Code introduced by
$numrows 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...
86
        $this_search = $listingHandler->getall($criteria);
0 ignored issues
show
Coding Style introduced by
$this_search does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
87
88
        $ret = [];
89
        $k   = 0;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $k. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
90
91
        foreach ($this_search as $obj) {
0 ignored issues
show
Coding Style introduced by
$this_search does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
92
            $ret[$k]['image'] = 'images/cat/default.gif';
93
            $ret[$k]['link']  = 'listing.php?lid=' . $obj->getVar('lid') . '';
94
            $ret[$k]['title'] = $obj->getVar('name') . ' ' . $obj->getVar('mname') . ' ' . $obj->getVar('lname') . '   ---   ' . $obj->getVar('school') . '
95
		---   ' . $obj->getVar('year');
96
            $ret[$k]['time']  = $obj->getVar('date');
97
            $ret[$k]['uid']   = $obj->getVar('usid');
98
            $k++;
99
        }
100
101
        return $ret;
102
    }
103
}
104