Conditions | 11 |
Paths | 48 |
Total Lines | 94 |
Code Lines | 70 |
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 declare(strict_types=1); |
||
33 | function suico_search( |
||
34 | $queryarray, |
||
35 | $andor, |
||
36 | $limit, |
||
37 | $offset, |
||
38 | $userid |
||
39 | ) { |
||
40 | global $xoopsDB, $module; |
||
41 | //getting the url to the uploads directory |
||
42 | $moduleHandler = xoops_getHandler('module'); |
||
43 | $modulo = $moduleHandler->getByDirname('suico'); |
||
|
|||
44 | /** @var \XoopsConfigHandler $configHandler */ |
||
45 | $configHandler = xoops_getHandler('config'); |
||
46 | $moduleConfig = $configHandler->getConfigsByCat(0, $modulo->getVar('mid')); |
||
47 | $path_uploadimages = XOOPS_UPLOAD_URL; |
||
48 | $ret = []; |
||
49 | $sql = 'SELECT image_id, title, caption, date_created, uid_owner, filename FROM ' . $xoopsDB->prefix( |
||
50 | 'suico_images' |
||
51 | ) . ' WHERE '; |
||
52 | if (0 !== $userid) { |
||
53 | $sql .= '(uid_owner =' . (int)$userid . ')'; |
||
54 | } |
||
55 | // because count() returns 1 even if a supplied variable |
||
56 | // is not an array, we must check if $querryarray is really an array |
||
57 | $count = count($queryarray); |
||
58 | if ($count > 0 && is_array($queryarray)) { |
||
59 | $sql .= " ((title LIKE '%" . $queryarray[0] . "%')"; |
||
60 | for ($i = 1; $i < $count; ++$i) { |
||
61 | $sql .= " {$andor} "; |
||
62 | $sql .= "(title LIKE '%" . $queryarray[$i] . "%')"; |
||
63 | } |
||
64 | $sql .= ') '; |
||
65 | } |
||
66 | $sql .= 'ORDER BY image_id DESC'; |
||
67 | //echo $sql; |
||
68 | //printr($xoopsModules); |
||
69 | $result = $xoopsDB->query($sql, $limit, $offset); |
||
70 | $i = 0; |
||
71 | $stringofimage = 'images/search.png">'; |
||
72 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
73 | if (0 !== $userid) { |
||
74 | if ($limit > 5) { |
||
75 | $ret[$i]['image'] = "assets/images/search.png'><a href='" |
||
76 | . XOOPS_URL |
||
77 | . '/modules/suico/album.php?uid=' |
||
78 | . $myrow['uid_owner'] |
||
79 | . "'><img src='" |
||
80 | . $path_uploadimages |
||
81 | . '/suico/images/thumb_' |
||
82 | . $myrow['filename'] |
||
83 | . "'></a><br>" |
||
84 | . '<img src=' |
||
85 | . XOOPS_URL |
||
86 | . '/modules/suico/images/search.png'; |
||
87 | $ret[$i]['link'] = 'album.php?uid=' . $myrow['uid_owner']; |
||
88 | $ret[$i]['title'] = $myrow['title']; |
||
89 | //$ret[$i]['time'] = $myrow['date_created']; |
||
90 | $ret[$i]['uid'] = $myrow['uid_owner']; |
||
91 | } else { |
||
92 | $stringofimage .= '<a href="' . XOOPS_URL . '/modules/suico/album.php?uid=' . $myrow['uid_owner'] . '" title="' . $myrow['title'] . '"><img src="' . $path_uploadimages . '/suico/images/thumb_' . $myrow['filename'] . '"></a> '; |
||
93 | } |
||
94 | } else { |
||
95 | $ret[$i]['image'] = "assets/images/search.png'><a href='" |
||
96 | . XOOPS_URL |
||
97 | . '/modules/suico/album.php?uid=' |
||
98 | . $myrow['uid_owner'] |
||
99 | . "'><img src='" |
||
100 | . $path_uploadimages |
||
101 | . '/suico/images/thumb_' |
||
102 | . $myrow['filename'] |
||
103 | . "'></a><br>" |
||
104 | . "<img src='" |
||
105 | . XOOPS_URL |
||
106 | . '/modules/suico/images/search.png'; |
||
107 | $ret[$i]['link'] = 'album.php?uid=' . $myrow['uid_owner']; |
||
108 | $ret[$i]['title'] = $myrow['title']; |
||
109 | //$ret[$i]['time'] = $myrow['date_created']; |
||
110 | $ret[$i]['uid'] = $myrow['uid_owner']; |
||
111 | } |
||
112 | $i++; |
||
113 | } |
||
114 | if (0 !== $userid && $i > 0) { |
||
115 | if ($limit < 6) { |
||
116 | $ret = []; |
||
117 | $ret[0]['title'] = 'See its album'; |
||
118 | $ret[0]['time'] = time(); |
||
119 | $ret[0]['uid'] = $userid; |
||
120 | $ret[0]['link'] = 'album.php?uid=' . $userid; |
||
121 | $stringofimage .= '<img src="' . XOOPS_URL . '/modules/suico/assets/images/search.png'; |
||
122 | $ret[0]['image'] = $stringofimage; |
||
123 | } |
||
124 | } |
||
125 | |||
126 | return $ret; |
||
127 | } |
||
128 |