Failed Conditions
Push — master ( 8ba584...d573fc )
by Travis
05:06
created

TopUsersController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 14 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use DB;
6
use Illuminate\Http\Request;
7
8
class TopUsersController extends Controller
9
{
10
    /**
11
     * List all of the top users.
12
     */
13
    public function index() {
14
        $topUsers = DB::table('snippets_votes')
15
            ->join('snippets', 'snippets.id', '=', 'snippets_votes.snippet_id')
16
            ->join('users', 'users.id', '=', 'snippets.user_id')
17
            ->select(DB::raw('count(*) as votes, name, username'))
18
            ->groupBy('snippets.user_id')
19
            ->orderBy('votes', 'desc')
20
            ->limit(10)
21
            ->get();
22
23
        return response()->json([
24
            'topUsers' => $topUsers,
25
        ]);
26
    }   
27
}
28