DiscussController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 43
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 5 1
A leaderboard() 0 23 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers\Discuss;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Support\Facades\Cache;
9
use Illuminate\View\View;
10
use Xetaravel\Models\Badge;
11
use Xetaravel\Models\User;
12
13
class DiscussController extends Controller
14
{
15
    /**
16
     * Display all conversations.
17
     * Handled by Livewire.
18
     *
19
     * @return View
20
     */
21
    public function index(): View
22
    {
23
        $breadcrumbs = $this->breadcrumbs;
24
25
        return view('Discuss::index', compact('breadcrumbs'));
26
    }
27
28
    /**
29
     * Display the Leaderboard.
30
     *
31
     * @return View
32
     */
33
    public function leaderboard(): View
34
    {
35
        $secondes = 1; //config('badges.users.pillarofcommunity.cache_lifetime_in_secondes'); // 86400 -> 24H
36
37
        $users = Cache::remember('Badges.users.pillarofcommunity', $secondes, function () {
38
            return User::with('account')
39
                ->whereDoesntHave('roles', function (Builder $query) {
40
                    $query->where('name', 'Banished'); // Select all user that does not have the role "banished"
41
                })
42
                ->orderBy('experiences_total', 'desc')
0 ignored issues
show
Bug introduced by
'experiences_total' of type string is incompatible with the type Closure|Illuminate\Datab...\Database\Query\Builder expected by parameter $column of Illuminate\Database\Query\Builder::orderBy(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
                ->orderBy(/** @scrutinizer ignore-type */ 'experiences_total', 'desc')
Loading history...
43
                ->limit(15)
44
                ->get();
45
        });
46
47
        $breadcrumbs = $this->breadcrumbs->addCrumb(
48
            '<svg class="inline w-5 h-5 mr-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M528 160l0 256c0 8.8-7.2 16-16 16l-192 0c0-44.2-35.8-80-80-80l-64 0c-44.2 0-80 35.8-80 80l-32 0c-8.8 0-16-7.2-16-16l0-256 480 0zM64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l448 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zM272 256a64 64 0 1 0 -128 0 64 64 0 1 0 128 0zm104-48c-13.3 0-24 10.7-24 24s10.7 24 24 24l80 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-80 0zm0 96c-13.3 0-24 10.7-24 24s10.7 24 24 24l80 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-80 0z"></path></svg>
49
            Leaderboard',
50
            route('discuss.leaderboard')
51
        );
52
53
        $badge = Badge::where('type', 'topLeaderboard')->first();
54
55
        return view('Discuss::leaderboard', compact('breadcrumbs', 'users', 'badge'));
56
    }
57
}
58