| Conditions | 11 |
| Paths | 12 |
| Total Lines | 43 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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); |
||
| 113 | public function getAllPictures( |
||
| 114 | $criteria = [], |
||
| 115 | $asobject = false, |
||
| 116 | $sort = 'cod_img', |
||
| 117 | $cat_order = 'ASC', |
||
| 118 | $limit = 0, |
||
| 119 | $start = 0 |
||
| 120 | ): array { |
||
| 121 | /** @var \XoopsMySQLDatabase $xoopsDB */ |
||
| 122 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 123 | $ret = []; |
||
| 124 | $where_query = ''; |
||
| 125 | if (\is_array($criteria) && \count($criteria) > 0) { |
||
| 126 | $where_query = ' WHERE'; |
||
| 127 | foreach ($criteria as $c) { |
||
| 128 | $where_query .= " {$c} AND"; |
||
| 129 | } |
||
| 130 | $where_query = \mb_substr($where_query, 0, -4); |
||
| 131 | } elseif (!\is_array($criteria) && $criteria) { |
||
| 132 | $where_query = " WHERE {$criteria}"; |
||
| 133 | } |
||
| 134 | if ($asobject) { |
||
| 135 | $sql = 'SELECT * FROM ' . $xoopsDB->prefix('adslight_pictures') . "{$where_query} ORDER BY {$sort} {$cat_order}"; |
||
| 136 | $result = $xoopsDB->query($sql, $limit, $start); |
||
| 137 | if ($xoopsDB->isResultSet($result)) { |
||
| 138 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 139 | $ret[] = new self($myrow); |
||
| 140 | } |
||
| 141 | } else { |
||
| 142 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
| 143 | } |
||
| 144 | } else { |
||
| 145 | $sql = 'SELECT cod_img FROM ' . $xoopsDB->prefix('adslight_pictures') . "{$where_query} ORDER BY {$sort} {$cat_order}"; |
||
| 146 | $result = $xoopsDB->query($sql, $limit, $start); |
||
| 147 | if (!$xoopsDB->isResultSet($result)) { |
||
| 148 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
| 149 | } |
||
| 150 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 151 | $ret[] = $myrow['cog_img']; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | return $ret; |
||
| 156 | } |
||
| 175 |