| Conditions | 3 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 31 |
| 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 |
||
| 99 | public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array |
||
| 100 | { |
||
| 101 | $myts = \MyTextSanitizer::getInstance(); |
||
| 102 | $ret = null; |
||
| 103 | $i = 0; |
||
| 104 | // For myalbum-p with thumbs enabled |
||
| 105 | |||
| 106 | $sql = 'SELECT p.lid, p.title, p.ext, p.date, t.description, c.cid, c.title as cat, p.submitter'; |
||
| 107 | $sql .= ' FROM ' . $xoopsDB->prefix('myalbum_photos') . ' p, '; |
||
| 108 | $sql .= $xoopsDB->prefix('myalbum_text') . ' t, '; |
||
| 109 | $sql .= $xoopsDB->prefix('myalbum_cat') . ' c '; |
||
| 110 | $sql .= 'WHERE p.status > 0 AND p.cid = c.cid AND p.lid = t.lid '; |
||
| 111 | $sql .= 'ORDER BY date DESC'; |
||
| 112 | $result = $xoopsDB->query($sql, $this->grab, 0); |
||
| 113 | if ($result instanceof \mysqli_result) { |
||
| 114 | $ret = []; |
||
| 115 | while (false !== ($row = $xoopsDB->fetchArray($result))) { |
||
| 116 | $link = XOOPS_URL . '/modules/' . $this->dirname . '/photo.php?lid=' . $row['lid']; |
||
| 117 | $thumb = XOOPS_URL . '/uploads/thumbs/' . $row['lid'] . '.' . $row['ext']; |
||
| 118 | $name = $this->myGetUnameFromId($row['submitter']); |
||
| 119 | $title = $myts->displayTarea($row['title']); |
||
| 120 | $cat = $myts->displayTarea($row['cat']); |
||
| 121 | $catlink = XOOPS_URL . '/modules/' . $this->dirname . '/viewcat.php?cid=' . $row['cid']; |
||
| 122 | /* |
||
| 123 | * Required elements of an RSS item |
||
| 124 | */ |
||
| 125 | // 1. Title of an item |
||
| 126 | $ret[$i]['title'] = $this->modname . ': ' . $title; |
||
| 127 | // 2. URL of an item |
||
| 128 | $ret[$i]['link'] = $link; |
||
| 129 | // 3. Item modification date, must be in Unix time format |
||
| 130 | $ret[$i]['timestamp'] = $row['date']; |
||
| 131 | // 4. The item synopsis, or description, whatever |
||
| 132 | $desc = '<p><a href="' . $link . '"><img src="' . $thumb . '" align="left" alt="' . $title . '" border="0"></a> '; |
||
| 133 | $desc .= 'By ' . $name . ' in <a href="' . $catlink . '">' . $cat . '</a><br>'; |
||
| 134 | $desc .= $myts->displayTarea($row['description']) . '</p><br clear="all">'; |
||
| 135 | $ret[$i]['description'] = $desc; |
||
| 136 | /* |
||
| 137 | * Optional elements of an RSS item |
||
| 138 | */ |
||
| 139 | // 5. The item synopsis, or description, whatever |
||
| 140 | $ret[$i]['guid'] = $link; |
||
| 141 | // 6. A string + domain that identifies a categorization taxonomy |
||
| 142 | $ret[$i]['category'] = $cat; |
||
| 143 | $ret[$i]['domain'] = $catlink; |
||
| 144 | |||
| 145 | $i++; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | return $ret; |
||
| 150 | } |
||
| 152 |