| Conditions | 13 |
| Paths | 4096 |
| Total Lines | 220 |
| Code Lines | 164 |
| 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 |
||
| 15 | public function show() |
||
| 16 | { |
||
| 17 | $lava_config = [ |
||
| 18 | 'legend' => [ |
||
| 19 | 'position' => 'in', |
||
| 20 | 'textStyle' => [ |
||
| 21 | 'color' => '#ffffe0', |
||
| 22 | ], |
||
| 23 | ], |
||
| 24 | 'backgroundColor' => [ |
||
| 25 | 'fill' => '#002B36', |
||
| 26 | ], |
||
| 27 | 'hAxis' => [ |
||
| 28 | 'textStyle' => [ |
||
| 29 | 'color' => '#ffffe0', |
||
| 30 | ], |
||
| 31 | ], |
||
| 32 | 'vAxis' => [ |
||
| 33 | 'textStyle' => [ |
||
| 34 | 'color' => '#ffffe0', |
||
| 35 | ], |
||
| 36 | ], |
||
| 37 | 'pointSize' => 5, |
||
| 38 | 'pointShape' => [ |
||
| 39 | 'type' => 'circle', |
||
| 40 | 'rotation' => 180, |
||
| 41 | ], |
||
| 42 | 'trendlines' => [ |
||
| 43 | 0 => [ |
||
| 44 | 'type' => 'line', |
||
| 45 | 'color' => 'red', |
||
| 46 | 'pointsVisible' => true, |
||
| 47 | 'pointSize' => 1, |
||
| 48 | ], |
||
| 49 | ], |
||
| 50 | ]; |
||
| 51 | |||
| 52 | $lava = new Lavacharts(); |
||
| 53 | |||
| 54 | // Anzahl der Registrierungen |
||
| 55 | $users = \DB::table('users') |
||
| 56 | ->selectRaw('YEAR(created_at) as year') |
||
| 57 | ->selectRaw('MONTH(created_at) as month') |
||
| 58 | ->selectRaw('COUNT(users.id) AS count') |
||
| 59 | ->orderBy('created_at') |
||
| 60 | ->groupBy(\DB::raw('YEAR(created_at)')) |
||
| 61 | ->groupBy(\DB::raw('MONTH(created_at)')) |
||
| 62 | ->get(); |
||
| 63 | $reg = $lava->DataTable(); |
||
|
|
|||
| 64 | $reg->addStringColumn('Datum') |
||
| 65 | ->addNumberColumn('Registrierungen pro Monat'); |
||
| 66 | foreach ($users as $user) { |
||
| 67 | $reg->addRow([$user->year.'-'.$user->month, $user->count]); |
||
| 68 | } |
||
| 69 | $lava->AreaChart('Registrierungen', $reg, $lava_config); |
||
| 70 | |||
| 71 | // Kommentare pro Monat |
||
| 72 | $comments = \DB::table('comments') |
||
| 73 | ->selectRaw('YEAR(created_at) as year') |
||
| 74 | ->selectRaw('MONTH(created_at) as month') |
||
| 75 | ->selectRaw('COUNT(id) AS count') |
||
| 76 | ->orderBy('created_at') |
||
| 77 | ->groupBy(\DB::raw('YEAR(created_at)')) |
||
| 78 | ->groupBy(\DB::raw('MONTH(created_at)')) |
||
| 79 | ->get(); |
||
| 80 | $com = $lava->DataTable(); |
||
| 81 | $com->addStringColumn('Datum') |
||
| 82 | ->addNumberColumn('Kommentare pro Monat'); |
||
| 83 | foreach ($comments as $comment) { |
||
| 84 | $com->addRow([$comment->year.'-'.$comment->month, $comment->count]); |
||
| 85 | } |
||
| 86 | $lava->AreaChart('Kommentare', $com, $lava_config); |
||
| 87 | |||
| 88 | // Kommentare pro Monat |
||
| 89 | $gamesperyear = \DB::table('games_files') |
||
| 90 | ->select('release_year as year') |
||
| 91 | ->selectRaw('COUNT(release_year) as count') |
||
| 92 | ->groupBy('release_year') |
||
| 93 | ->orderBy('release_year') |
||
| 94 | ->get(); |
||
| 95 | $com = $lava->DataTable(); |
||
| 96 | $com->addStringColumn('Datum') |
||
| 97 | ->addNumberColumn('Releases pro Jahr'); |
||
| 98 | foreach ($gamesperyear as $game) { |
||
| 99 | $com->addRow([$game->year, $game->count]); |
||
| 100 | } |
||
| 101 | $lava->AreaChart('Releases', $com, $lava_config); |
||
| 102 | |||
| 103 | // Kommentare pro Monat |
||
| 104 | $gamespermonth = \DB::table('games_files') |
||
| 105 | ->select('release_month as year') |
||
| 106 | ->selectRaw('COUNT(release_month) as count') |
||
| 107 | ->groupBy('release_month') |
||
| 108 | ->orderBy('release_month') |
||
| 109 | ->get(); |
||
| 110 | $com = $lava->DataTable(); |
||
| 111 | $com->addStringColumn('Datum') |
||
| 112 | ->addNumberColumn('Releases pro Monat'); |
||
| 113 | foreach ($gamespermonth as $game) { |
||
| 114 | $com->addRow([$game->year, $game->count]); |
||
| 115 | } |
||
| 116 | $lava->AreaChart('ReleasesMon', $com, $lava_config); |
||
| 117 | |||
| 118 | //Forenposts pro Monat |
||
| 119 | // Kommentare pro Monat |
||
| 120 | $postspermonth = \DB::table('board_posts') |
||
| 121 | ->selectRaw('YEAR(created_at) as year') |
||
| 122 | ->selectRaw('MONTH(created_at) as month') |
||
| 123 | ->selectRaw('COUNT(id) AS count') |
||
| 124 | ->orderBy('created_at') |
||
| 125 | ->groupBy(\DB::raw('YEAR(created_at)')) |
||
| 126 | ->groupBy(\DB::raw('MONTH(created_at)')) |
||
| 127 | ->get(); |
||
| 128 | $com = $lava->DataTable(); |
||
| 129 | $com->addStringColumn('Datum') |
||
| 130 | ->addNumberColumn('Forenposts pro Monat'); |
||
| 131 | foreach ($postspermonth as $p) { |
||
| 132 | $com->addRow([$p->year.'-'.$p->month, $p->count]); |
||
| 133 | } |
||
| 134 | $lava->AreaChart('ForumPosts', $com, $lava_config); |
||
| 135 | |||
| 136 | $filesize = [ |
||
| 137 | 'attach' => [ |
||
| 138 | 'size' => 0, |
||
| 139 | 'count' => 0, |
||
| 140 | ], |
||
| 141 | 'screens' => [ |
||
| 142 | 'size' => 0, |
||
| 143 | 'count' => 0, |
||
| 144 | ], |
||
| 145 | 'games' => [ |
||
| 146 | 'size' => 0, |
||
| 147 | 'count' => 0, |
||
| 148 | ], |
||
| 149 | 'logos' => [ |
||
| 150 | 'size' => 0, |
||
| 151 | 'count' => 0, |
||
| 152 | ], |
||
| 153 | 'resources' => [ |
||
| 154 | 'size' => 0, |
||
| 155 | 'count' => 0, |
||
| 156 | ], |
||
| 157 | 'sum' => [ |
||
| 158 | 'size' => 0, |
||
| 159 | 'count' => 0, |
||
| 160 | ], |
||
| 161 | ]; |
||
| 162 | |||
| 163 | $files = \Storage::files('attachments'); |
||
| 164 | foreach ($files as $f) { |
||
| 165 | $filesize['attach']['size'] += \Storage::size($f); |
||
| 166 | } |
||
| 167 | $filesize['attach']['count'] = count($files); |
||
| 168 | $filesize['sum']['size'] += $filesize['attach']['size']; |
||
| 169 | $filesize['sum']['count'] += $filesize['attach']['count']; |
||
| 170 | |||
| 171 | $files = \Storage::files('screenshots'); |
||
| 172 | foreach ($files as $f) { |
||
| 173 | $filesize['screens']['size'] += \Storage::size($f); |
||
| 174 | } |
||
| 175 | $filesize['screens']['count'] = count($files); |
||
| 176 | $filesize['sum']['size'] += $filesize['screens']['size']; |
||
| 177 | $filesize['sum']['count'] += $filesize['screens']['count']; |
||
| 178 | |||
| 179 | $files = \Storage::files('games'); |
||
| 180 | foreach ($files as $f) { |
||
| 181 | $filesize['games']['size'] += \Storage::size($f); |
||
| 182 | } |
||
| 183 | $filesize['games']['count'] = count($files); |
||
| 184 | $filesize['sum']['size'] += $filesize['games']['size']; |
||
| 185 | $filesize['sum']['count'] += $filesize['games']['count']; |
||
| 186 | |||
| 187 | $files = \Storage::files('logos'); |
||
| 188 | foreach ($files as $f) { |
||
| 189 | $filesize['logos']['size'] += \Storage::size($f); |
||
| 190 | } |
||
| 191 | $filesize['logos']['count'] = count($files); |
||
| 192 | $filesize['sum']['size'] += $filesize['logos']['size']; |
||
| 193 | $filesize['sum']['count'] += $filesize['logos']['count']; |
||
| 194 | |||
| 195 | $files = \Storage::files('resources'); |
||
| 196 | foreach ($files as $f) { |
||
| 197 | $filesize['resources']['size'] += \Storage::size($f); |
||
| 198 | } |
||
| 199 | $filesize['resources']['count'] = count($files); |
||
| 200 | $filesize['sum']['size'] += $filesize['resources']['size']; |
||
| 201 | $filesize['sum']['count'] += $filesize['resources']['count']; |
||
| 202 | |||
| 203 | // Augeteilt nach Maker |
||
| 204 | $makerchart = Maker::all(); |
||
| 205 | $com = $lava->DataTable(); |
||
| 206 | $com->addStringColumn('Maker') |
||
| 207 | ->addNumberColumn('Spieleanzahl'); |
||
| 208 | foreach ($makerchart as $maker) { |
||
| 209 | $com->addRow([$maker->title, $maker->games->count()]); |
||
| 210 | } |
||
| 211 | $lava->PieChart('MakerChart', $com, $lava_config); |
||
| 212 | |||
| 213 | // Kelven Stats... |
||
| 214 | $gamesperyear = \DB::table('games_files') |
||
| 215 | ->leftJoin('games_developer', 'games_developer.game_id', '=', 'games_files.game_id') |
||
| 216 | ->select('games_files.release_year as year') |
||
| 217 | ->selectRaw('COUNT(games_files.release_year) as count') |
||
| 218 | ->where('games_developer.developer_id', '=', 6) |
||
| 219 | ->groupBy('games_files.release_year') |
||
| 220 | ->orderBy('games_files.release_year') |
||
| 221 | ->get(); |
||
| 222 | $com = $lava->DataTable(); |
||
| 223 | $com->addStringColumn('Datum') |
||
| 224 | ->addNumberColumn('Releases pro Jahr'); |
||
| 225 | foreach ($gamesperyear as $game) { |
||
| 226 | $com->addRow([$game->year, $game->count]); |
||
| 227 | } |
||
| 228 | $lava->AreaChart('PlayerReleases', $com, $lava_config); |
||
| 229 | |||
| 230 | return view('statistics.index', [ |
||
| 231 | 'lava' => $lava, |
||
| 232 | 'files' => $filesize, |
||
| 233 | ]); |
||
| 234 | } |
||
| 235 | } |
||
| 236 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.