| Conditions | 3 |
| Paths | 4 |
| Total Lines | 82 |
| Code Lines | 71 |
| 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 |
||
| 190 | public function getRandomLink($ignore_category = null) { |
||
| 191 | if (isset($ignore_category)) { |
||
| 192 | $stmt = \AL\Db\execute_query( |
||
| 193 | "LinkDAO: Get random link", |
||
| 194 | $this->mysqli, |
||
| 195 | "SELECT website.website_id, |
||
| 196 | website.website_name, |
||
| 197 | website.website_url, |
||
| 198 | website.website_imgext, |
||
| 199 | website.website_date, |
||
| 200 | website.description, |
||
| 201 | website.inactive, |
||
| 202 | users.userid, |
||
| 203 | users.user_id |
||
| 204 | FROM website |
||
| 205 | LEFT JOIN website_category_cross ON |
||
| 206 | (website.website_id = website_category_cross.website_id) |
||
| 207 | LEFT JOIN website_category ON |
||
| 208 | (website_category.website_category_id = website_category_cross.website_category_id) |
||
| 209 | LEFT JOIN users ON ( website.user_id = users.user_id ) |
||
| 210 | WHERE website.website_imgext <> ' ' and website.inactive = 0 |
||
| 211 | and website_category.website_category_name <> ? |
||
| 212 | ORDER BY RAND() LIMIT 1", "s", $ignore_category |
||
| 213 | ); |
||
| 214 | } else { |
||
| 215 | $stmt = \AL\Db\execute_query( |
||
| 216 | "LinkDAO: Get random link", |
||
| 217 | $this->mysqli, |
||
| 218 | "SELECT website.website_id, |
||
| 219 | website.website_name, |
||
| 220 | website.website_url, |
||
| 221 | website.website_imgext, |
||
| 222 | website.website_date, |
||
| 223 | website.description, |
||
| 224 | website.inactive, |
||
| 225 | users.userid, |
||
| 226 | users.user_id |
||
| 227 | FROM website |
||
| 228 | LEFT JOIN website_category_cross ON |
||
| 229 | (website.website_id = website_category_cross.website_id) |
||
| 230 | LEFT JOIN website_category ON |
||
| 231 | (website_category.website_category_id = website_category_cross.website_category_id) |
||
| 232 | LEFT JOIN users ON ( website.user_id = users.user_id ) |
||
| 233 | WHERE website.website_imgext <> ' ' and website.inactive = 0 |
||
| 234 | ORDER BY RAND() LIMIT 1". |
||
| 235 | null, null |
||
| 236 | ); |
||
| 237 | } |
||
| 238 | |||
| 239 | \AL\Db\bind_result( |
||
| 240 | "LinkDAO: Get random link", |
||
| 241 | $stmt, |
||
| 242 | $id, |
||
| 243 | $name, |
||
| 244 | $url, |
||
| 245 | $imgext, |
||
| 246 | $date, |
||
| 247 | $description, |
||
| 248 | $inactive, |
||
| 249 | $user, |
||
| 250 | $userid |
||
| 251 | ); |
||
| 252 | |||
| 253 | $link = null; |
||
| 254 | if ($stmt->fetch()) { |
||
| 255 | $link = new \AL\Common\Model\Link\Link( |
||
| 256 | $id, |
||
| 257 | $name, |
||
| 258 | $url, |
||
| 259 | $description, |
||
| 260 | $imgext, |
||
| 261 | $inactive, |
||
| 262 | $user, |
||
| 263 | $date, |
||
| 264 | $userid, |
||
| 265 | null |
||
| 266 | ); |
||
| 267 | } |
||
| 268 | |||
| 269 | $stmt->close(); |
||
| 270 | |||
| 271 | return $link; |
||
| 272 | } |
||
| 274 |