Conditions | 11 |
Paths | 33 |
Total Lines | 75 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 declare(strict_types=1); |
||
47 | function xoopsfaq_search($queryarray, $andor, $limit, $offset, $userid) |
||
48 | { |
||
49 | $ret = []; |
||
50 | if (0 != $userid) { |
||
51 | return $ret; |
||
52 | } |
||
53 | |||
54 | /** @var CategoryHandler $categoryHandler */ |
||
55 | /** @var ContentsHandler $contentsHandler */ |
||
56 | /** @var Helper $helper */ |
||
57 | $helper = Helper::getInstance(); |
||
58 | |||
59 | // Find the search term in the Category |
||
60 | // Find the search term in the FAQ |
||
61 | $categoryHandler = $helper->getHandler('Category'); |
||
62 | $contentFields = ['category_id', 'category_title']; |
||
63 | $criteria = new \CriteriaCompo(); |
||
64 | $criteria->setSort('category_title'); |
||
65 | $criteria->order = 'ASC'; |
||
66 | $criteria->setLimit((int)$limit); |
||
67 | $criteria->setStart((int)$offset); |
||
68 | |||
69 | $queryarrayHold = $queryarray; |
||
70 | if ((is_array($queryarray)) && !empty($queryarray)) { |
||
71 | $criteria->add(new \Criteria('category_title', '%' . $queryarray[0] . '%', 'LIKE')); |
||
72 | array_shift($queryarray); //get rid of first element |
||
73 | foreach ($queryarray as $query) { |
||
74 | $criteria->add(new \Criteria('category_title', '%' . $query . '%', 'LIKE'), $andor); |
||
75 | } |
||
76 | } |
||
77 | $catArray = $categoryHandler->getAll($criteria, $contentFields, false); |
||
78 | $catCount = !empty($catArray) ? count($catArray) : 0; |
||
79 | $totalLimit = (int)$limit - $catCount; |
||
80 | foreach ($catArray as $cId => $cat) { |
||
81 | $ret[] = [ |
||
82 | 'image' => 'assets/images/folder.png', |
||
83 | 'link' => $helper->url('index.php?cat_id=' . $cId), |
||
84 | 'title' => $cat['category_title'], |
||
85 | ]; |
||
86 | } |
||
87 | unset($catArray); |
||
88 | |||
89 | // Find the search term in the FAQ |
||
90 | $queryarray = $queryarrayHold; |
||
91 | $contentsHandler = $helper->getHandler('Contents'); |
||
92 | $contentFields = ['contents_id', 'contents_cid', 'contents_title', 'contents_contents', 'contents_publish']; |
||
93 | $criteria = new \CriteriaCompo(); |
||
94 | $criteria->add(new \Criteria('contents_active', Constants::ACTIVE, '=')); |
||
95 | $criteria->setSort('contents_id'); |
||
96 | $criteria->order = 'DESC'; |
||
97 | $criteria->setLimit($totalLimit); |
||
98 | $criteria->setStart((int)$offset); |
||
99 | |||
100 | if ((is_array($queryarray)) && !empty($queryarray)) { |
||
101 | $criteria->add(new \Criteria('contents_title', '%' . $queryarray[0] . '%', 'LIKE')); |
||
102 | $criteria->add(new \Criteria('contents_contents', '%' . $queryarray[0] . '%', 'LIKE'), 'OR'); |
||
103 | array_shift($queryarray); //get rid of first element |
||
104 | |||
105 | foreach ($queryarray as $query) { |
||
106 | $criteria->add(new \Criteria('contents_title', '%' . $query . '%', 'LIKE'), $andor); |
||
107 | $criteria->add(new \Criteria('contents_contents', '%' . $query . '%', 'LIKE'), 'OR'); |
||
108 | } |
||
109 | } |
||
110 | $contentArray = $contentsHandler->getAll($criteria, $contentFields, false); |
||
111 | foreach ($contentArray as $content) { |
||
112 | $ret[] = [ |
||
113 | 'image' => 'assets/images/question2.gif', |
||
114 | 'link' => $helper->url('index.php?cat_id=' . $content['contents_cid'] . '#q' . $content['contents_id']), |
||
115 | 'title' => $content['contents_title'], |
||
116 | 'time' => $content['contents_publish'], |
||
117 | ]; |
||
118 | } |
||
119 | unset($contentArray); |
||
120 | |||
121 | return $ret; |
||
122 | } |
||
123 |