| Conditions | 10 |
| Paths | 4 |
| Total Lines | 55 |
| Code Lines | 48 |
| 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 |
||
| 31 | public function getRss($cat, $videosId, $aniDbID, int $userID = 0, int $airDate = -1, int $limit = 100, int $offset = 0): mixed |
||
| 32 | { |
||
| 33 | $catSearch = $cartSearch = ''; |
||
| 34 | $catLimit = 'AND r.categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER; |
||
| 35 | if (\count($cat)) { |
||
| 36 | if ((int) $cat[0] === -2) { |
||
| 37 | $cartSearch = sprintf( |
||
| 38 | 'INNER JOIN users_releases ON users_releases.users_id = %d AND users_releases.releases_id = r.id', |
||
| 39 | $userID |
||
| 40 | ); |
||
| 41 | } elseif ((int) $cat[0] !== -1) { |
||
| 42 | $catSearch = Category::getCategorySearch($cat); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | $sql = |
||
| 46 | sprintf( |
||
| 47 | "SELECT r.searchname, r.guid, r.postdate, r.categories_id, r.size, r.totalpart, r.fromname, r.passwordstatus, r.grabs, r.comments, r.adddate, r.videos_id, r.tv_episodes_id, |
||
| 48 | m.cover, m.imdbid, m.rating, m.plot, m.year, m.genre, m.director, m.actors, |
||
| 49 | g.name AS group_name, |
||
| 50 | CONCAT(cp.title, ' > ', c.title) AS category_name, |
||
| 51 | COALESCE(cp.id,0) AS parentid, |
||
| 52 | mu.title AS mu_title, mu.url AS mu_url, mu.artist AS mu_artist, |
||
| 53 | mu.publisher AS mu_publisher, mu.releasedate AS mu_releasedate, |
||
| 54 | mu.review AS mu_review, mu.tracks AS mu_tracks, mu.cover AS mu_cover, |
||
| 55 | mug.title AS mu_genre, co.title AS co_title, co.url AS co_url, |
||
| 56 | co.publisher AS co_publisher, co.releasedate AS co_releasedate, |
||
| 57 | co.review AS co_review, co.cover AS co_cover, cog.title AS co_genre, |
||
| 58 | bo.cover AS bo_cover |
||
| 59 | FROM releases r |
||
| 60 | LEFT JOIN categories c ON c.id = r.categories_id |
||
| 61 | INNER JOIN root_categories cp ON cp.id = c.root_categories_id |
||
| 62 | LEFT JOIN usenet_groups g ON g.id = r.groups_id |
||
| 63 | LEFT OUTER JOIN musicinfo mu ON mu.id = r.musicinfo_id |
||
| 64 | LEFT OUTER JOIN genres mug ON mug.id = mu.genres_id |
||
| 65 | LEFT OUTER JOIN consoleinfo co ON co.id = r.consoleinfo_id |
||
| 66 | LEFT JOIN movieinfo m ON m.id = r.movieinfo_id |
||
| 67 | LEFT OUTER JOIN genres cog ON cog.id = co.genres_id %s |
||
| 68 | LEFT OUTER JOIN tv_episodes tve ON tve.id = r.tv_episodes_id |
||
| 69 | LEFT OUTER JOIN bookinfo bo ON bo.id = r.bookinfo_id |
||
| 70 | WHERE r.passwordstatus %s |
||
| 71 | AND r.nzbstatus = %d |
||
| 72 | %s %s %s %s |
||
| 73 | ORDER BY postdate DESC %s", |
||
| 74 | $cartSearch, |
||
| 75 | $this->releases->showPasswords(), |
||
| 76 | NZB::NZB_ADDED, |
||
| 77 | $catSearch, |
||
| 78 | ($videosId > 0 ? sprintf('AND r.videos_id = %d %s', $videosId, ($catSearch === '' ? $catLimit : '')) : ''), |
||
| 79 | ($aniDbID > 0 ? sprintf('AND r.anidbid = %d %s', $aniDbID, ($catSearch === '' ? $catLimit : '')) : ''), |
||
| 80 | ($airDate > -1 ? sprintf('AND tve.firstaired >= DATE_SUB(CURDATE(), INTERVAL %d DAY)', $airDate) : ''), |
||
| 81 | $limit === -1 ? '' : ' LIMIT '.$limit.' OFFSET '.$offset |
||
| 82 | ); |
||
| 83 | |||
| 84 | return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) { |
||
| 85 | return Release::fromQuery($sql); |
||
| 86 | }); |
||
| 187 |