Conditions | 9 |
Paths | 23 |
Total Lines | 52 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
96 | public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array |
||
97 | { |
||
98 | $ret = null; |
||
99 | |||
100 | $i = -1; |
||
101 | $lasttime = false; |
||
102 | $lastuser = false; |
||
103 | $limit = 10 * $this->grab; |
||
104 | |||
105 | $sql = "SELECT uid, id, surname, notes, DATE_FORMAT(changed_ts,'%Y-%m-%d') as changedate FROM " . $xoopsDB->prefix('surnames'); |
||
106 | $sql .= ' WHERE approved=1 ORDER BY changedate DESC, uid '; |
||
107 | $result = $xoopsDB->query($sql, $limit, 0); |
||
108 | if ($result instanceof \mysqli_result) { |
||
109 | $ret = []; |
||
110 | while (false !== ($row = $xoopsDB->fetchArray($result))) { |
||
111 | $changedate = \strtotime($row['changedate']); |
||
112 | $uid = $row['uid']; |
||
113 | if ($lasttime == $changedate && $lastuser == $uid) { |
||
114 | $link = XOOPS_URL . '/modules/surnames/view.php?id=' . $row['id']; |
||
115 | $surname = $row['surname']; |
||
116 | $desc .= "<a href=\"$link\">$surname</a><br>"; |
||
|
|||
117 | } else { |
||
118 | if ($i >= 0) { |
||
119 | $ret[$i]['description'] = $desc; |
||
120 | } |
||
121 | ++$i; |
||
122 | $lasttime = $changedate; |
||
123 | $lastuser = $uid; |
||
124 | if ($i <= $this->grab) { |
||
125 | $desc = ''; |
||
126 | $name = $this->myGetUnameFromId($row['uid']); |
||
127 | $ret[$i]['title'] = $this->modname . ': by ' . $name; |
||
128 | $ret[$i]['link'] = XOOPS_URL . '/modules/surnames/list.php?uid=' . $row['uid']; |
||
129 | $ret[$i]['timestamp'] = $changedate; |
||
130 | |||
131 | $link = XOOPS_URL . '/modules/surnames/view.php?id=' . $row['id']; |
||
132 | $ret[$i]['guid'] = $link; |
||
133 | $ret[$i]['category'] = $this->modname; |
||
134 | |||
135 | $surname = $row['surname']; |
||
136 | $desc .= "<a href=\"$link\">$surname</a><br>"; |
||
137 | } |
||
138 | } |
||
139 | if ($i > $this->grab) { |
||
140 | break; |
||
141 | } |
||
142 | } |
||
143 | if ($i < $this->grab) { |
||
144 | $ret[$i]['description'] = $desc; |
||
145 | } |
||
146 | } |
||
147 | return $ret; |
||
148 | } |
||
150 |