Conditions | 2 |
Paths | 2 |
Total Lines | 54 |
Code Lines | 47 |
Lines | 54 |
Ratio | 100 % |
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 |
||
22 | View Code Duplication | public function showGames($tagid) { |
|
|
|||
23 | $games = \DB::table('games') |
||
24 | ->leftJoin('games_developer', 'games.id', '=', 'games_developer.game_id') |
||
25 | ->leftJoin('developer', 'games_developer.developer_id', '=', 'developer.id') |
||
26 | ->leftJoin('makers', 'makers.id', '=', 'games.maker_id') |
||
27 | ->leftJoin('tag_relations', function($join) { |
||
28 | $join->on('tag_relations.content_id', '=', 'games.id'); |
||
29 | $join->on('tag_relations.content_type', '=', \DB::raw("'game'")); |
||
30 | }) |
||
31 | ->leftJoin('tags', 'tag_relations.tag_id', '=', 'tags.id') |
||
32 | ->leftJoin('games_files', 'games_files.game_id', '=', 'games.id') |
||
33 | ->leftJoin('users', 'games_developer.user_id', '=', 'users.id') |
||
34 | ->select([ |
||
35 | 'games.id as gameid', |
||
36 | 'games.title as gametitle', |
||
37 | 'games.subtitle as gamesubtitle', |
||
38 | 'developer.name as developername', |
||
39 | 'developer.id as developerid', |
||
40 | 'developer.created_at as developerdate', |
||
41 | 'developer.user_id as developeruserid', |
||
42 | 'users.name as developerusername', |
||
43 | 'games.created_at as gamecreated_at', |
||
44 | 'makers.short as makershort', |
||
45 | 'makers.title as makertitle', |
||
46 | 'makers.id as makerid', |
||
47 | 'games.views as views', |
||
48 | 'tags.title as tag', |
||
49 | ]) |
||
50 | ->selectRaw('(SELECT COUNT(id) FROM comments WHERE content_id = games.id AND content_type = "game") as commentcount') |
||
51 | ->selectRaw('(SELECT SUM(vote_up) FROM comments WHERE content_id = games.id AND content_type = "game") as voteup') |
||
52 | ->selectRaw('(SELECT SUM(vote_down) FROM comments WHERE content_id = games.id AND content_type = "game") as votedown') |
||
53 | ->selectRaw('MAX(games_files.release_type) as gametype') |
||
54 | ->selectRaw("(SELECT STR_TO_DATE(CONCAT(release_year,'-',release_month,'-',release_day ), '%Y-%m-%d') FROM games_files WHERE game_id = games.id ORDER BY release_year DESC, release_month DESC, release_day DESC LIMIT 1) as releasedate") |
||
55 | ->selectRaw('(SELECT COUNT(id) FROM games_coupdecoeur WHERE game_id = games.id) as cdccount') |
||
56 | ->where('tags.id', '=', $tagid) |
||
57 | ->orderBy('games.title') |
||
58 | ->groupBy('games.id') |
||
59 | ->get(); |
||
60 | |||
61 | $gametypes = \DB::table('games_files_types') |
||
62 | ->select('id', 'title', 'short') |
||
63 | ->get(); |
||
64 | $gtypes = array(); |
||
65 | foreach ($gametypes as $gt) { |
||
66 | $t['title'] = $gt->title; |
||
67 | $t['short'] = $gt->short; |
||
68 | $gtypes[$gt->id] = $t; |
||
69 | } |
||
70 | |||
71 | return view('tags.show', [ |
||
72 | 'games' => $games, |
||
73 | 'gametypes' => $gtypes, |
||
74 | ]); |
||
75 | } |
||
76 | |||
105 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.