Conditions | 23 |
Paths | 9216 |
Total Lines | 122 |
Code Lines | 89 |
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 |
||
39 | function wgfilemanager_search($queryarray, $andor, $limit, $offset, $userid) |
||
40 | { |
||
41 | $ret = []; |
||
42 | $helper = \XoopsModules\Wgfilemanager\Helper::getInstance(); |
||
43 | |||
44 | // search in table file |
||
45 | // search keywords |
||
46 | $elementCount = 0; |
||
47 | $fileHandler = $helper->getHandler('File'); |
||
48 | if (\is_array($queryarray)) { |
||
49 | $elementCount = \count($queryarray); |
||
50 | } |
||
51 | if ($elementCount > 0) { |
||
52 | $crKeywords = new \CriteriaCompo(); |
||
53 | for ($i = 0; $i < $elementCount; $i++) { |
||
54 | $crKeyword = new \CriteriaCompo(); |
||
55 | if ('exact' === $andor) { |
||
56 | $crKeyword->add(new \Criteria('name', $queryarray[$i])); |
||
57 | $crKeyword->add(new \Criteria('name', $queryarray[$i])); |
||
58 | } else { |
||
59 | $crKeyword->add(new \Criteria('name', '%' . $queryarray[$i] . '%', 'LIKE')); |
||
60 | $crKeyword->add(new \Criteria('description', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
61 | } |
||
62 | $crKeywords->add($crKeyword, $andor); |
||
63 | unset($crKeyword); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | // search user(s) |
||
68 | if ($userid && \is_array($userid)) { |
||
69 | $userid = array_map('\intval', $userid); |
||
70 | $crUser = new \CriteriaCompo(); |
||
71 | $crUser->add(new \Criteria('submitter', '(' . \implode(',', $userid) . ')', 'IN'), 'OR'); |
||
72 | } elseif (is_numeric($userid) && $userid > 0) { |
||
73 | $crUser = new \CriteriaCompo(); |
||
74 | $crUser->add(new \Criteria('submitter', $userid), 'OR'); |
||
75 | } |
||
76 | |||
77 | $crSearch = new \CriteriaCompo(); |
||
78 | if (isset($crKeywords)) { |
||
79 | $crSearch->add($crKeywords); |
||
80 | } |
||
81 | if (isset($crUser)) { |
||
82 | $crSearch->add($crUser); |
||
83 | } |
||
84 | $crSearch->setStart($offset); |
||
85 | $crSearch->setLimit($limit); |
||
86 | $crSearch->setSort('date_created'); |
||
87 | $crSearch->setOrder('DESC'); |
||
88 | $fileAll = $fileHandler->getAll($crSearch); |
||
89 | foreach (\array_keys($fileAll) as $i) { |
||
90 | $ret[] = [ |
||
91 | 'image' => 'assets/icons/16/file.png', |
||
92 | 'link' => 'file.php?op=show&file_id=' . $fileAll[$i]->getVar('id') . '&dir_id=' . $fileAll[$i]->getVar('directory_id'), |
||
93 | 'title' => $fileAll[$i]->getVar('name'), |
||
94 | 'time' => $fileAll[$i]->getVar('date_created') |
||
95 | ]; |
||
96 | } |
||
97 | unset($crKeywords); |
||
98 | unset($crKeyword); |
||
99 | unset($crUser); |
||
100 | unset($crSearch); |
||
101 | |||
102 | // search in table directory |
||
103 | // search keywords |
||
104 | $elementCount = 0; |
||
105 | $directoryHandler = $helper->getHandler('Directory'); |
||
106 | if (\is_array($queryarray)) { |
||
107 | $elementCount = \count($queryarray); |
||
108 | } |
||
109 | if ($elementCount > 0) { |
||
110 | $crKeywords = new \CriteriaCompo(); |
||
111 | for ($i = 0; $i < $elementCount; $i++) { |
||
112 | $crKeyword = new \CriteriaCompo(); |
||
113 | if ('exact' === $andor) { |
||
114 | $crKeyword->add(new \Criteria('name', $queryarray[$i])); |
||
115 | $crKeyword->add(new \Criteria('name', $queryarray[$i])); |
||
116 | } else { |
||
117 | $crKeyword->add(new \Criteria('name', '%' . $queryarray[$i] . '%', 'LIKE')); |
||
118 | $crKeyword->add(new \Criteria('description', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
119 | } |
||
120 | $crKeywords->add($crKeyword, $andor); |
||
121 | unset($crKeyword); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | // search user(s) |
||
126 | if ($userid && \is_array($userid)) { |
||
127 | $userid = array_map('\intval', $userid); |
||
128 | $crUser = new \CriteriaCompo(); |
||
129 | $crUser->add(new \Criteria('submitter', '(' . \implode(',', $userid) . ')', 'IN'), 'OR'); |
||
130 | } elseif (is_numeric($userid) && $userid > 0) { |
||
131 | $crUser = new \CriteriaCompo(); |
||
132 | $crUser->add(new \Criteria('submitter', $userid), 'OR'); |
||
133 | } |
||
134 | |||
135 | $crSearch = new \CriteriaCompo(); |
||
136 | if (isset($crKeywords)) { |
||
137 | $crSearch->add($crKeywords); |
||
138 | } |
||
139 | if (isset($crUser)) { |
||
140 | $crSearch->add($crUser); |
||
141 | } |
||
142 | $crSearch->setStart($offset); |
||
143 | $crSearch->setLimit($limit); |
||
144 | $crSearch->setSort('date_created'); |
||
145 | $crSearch->setOrder('DESC'); |
||
146 | $directoryAll = $directoryHandler->getAll($crSearch); |
||
147 | foreach (\array_keys($directoryAll) as $i) { |
||
148 | $ret[] = [ |
||
149 | 'image' => 'assets/icons/16/folder.png', |
||
150 | 'link' => 'directory.php?op=list&dir_id=' . $directoryAll[$i]->getVar('id'), |
||
151 | 'title' => $directoryAll[$i]->getVar('name'), |
||
152 | 'time' => $directoryAll[$i]->getVar('date_created') |
||
153 | ]; |
||
154 | } |
||
155 | unset($crKeywords); |
||
156 | unset($crKeyword); |
||
157 | unset($crUser); |
||
158 | unset($crSearch); |
||
159 | |||
160 | return $ret; |
||
161 | |||
163 |