Conditions | 8 |
Paths | 20 |
Total Lines | 64 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
39 | public function search($queries, $andor, $limit, $start, $userid) |
||
40 | { |
||
41 | $xoops = Xoops::getInstance(); |
||
42 | $alumni = Alumni::getInstance(); |
||
43 | $myts = MyTextSanitizer::getInstance(); |
||
44 | $by_cat = Request::getInt('by_cat', ''); |
||
45 | $andor = Request::getWord('andor', 'AND'); |
||
46 | $queries = []; |
||
47 | $query = Request::getString('query', ''); |
||
48 | $start = Request::getInt('start', '0'); |
||
49 | |||
50 | $helper = Xoops::getModuleHelper('alumni'); |
||
51 | $module_id = $helper->getModule()->getVar('mid'); |
||
52 | $listingHandler = $helper->getHandler('listing'); |
||
53 | $groups = $xoops->getUserGroups(); |
||
54 | $alumni_ids = $xoops->getHandlerGroupperm()->getItemIds('alumni_view', $groups, $module_id); |
||
55 | $all_ids = implode(', ', $alumni_ids); |
||
56 | |||
57 | $criteria = new CriteriaCompo(); |
||
58 | $criteria->add(new Criteria('valid', 1, '=')); |
||
59 | // $criteria->add(new Criteria('date', time(), '<=')); |
||
60 | $criteria->add(new Criteria('cid', '(' . $all_ids . ')', 'IN')); |
||
61 | if (0 != $userid) { |
||
62 | $criteria->add(new Criteria('usid', $userid, '=')); |
||
63 | } |
||
64 | if ($by_cat) { |
||
65 | $criteria->add(new Criteria('cid', $by_cat, '=')); |
||
66 | } |
||
67 | |||
68 | $queries = [$query]; |
||
69 | $queries = implode('+', $queries); |
||
70 | |||
71 | $count = 0; |
||
72 | $i = 0; |
||
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(); |
||
86 | $this_search = $listingHandler->getall($criteria); |
||
87 | |||
88 | $ret = []; |
||
89 | $k = 0; |
||
90 | |||
91 | foreach ($this_search as $obj) { |
||
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 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.