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