MembersPanel   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 37
ccs 0
cts 20
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 22 1
A createModel() 0 5 1
1
<?php
2
3
namespace Terranet\Administrator\Dashboard\Panels;
4
5
use DB;
6
use Terranet\Administrator\Architect;
7
use Terranet\Administrator\Dashboard\Panel;
8
use Terranet\Administrator\Traits\Stringify;
9
10
class MembersPanel extends Panel
11
{
12
    use Stringify;
13
14
    public function render()
15
    {
16
        $weekAgo = \Carbon\Carbon::now()->subWeek();
17
        $monthAgo = \Carbon\Carbon::now()->subMonth();
18
19
        $total = $this->createModel()->count();
20
        $signedLastWeek = $this->createModel()
21
                                 ->where('created_at', '>=', $weekAgo)->count();
22
        $signedLastMonth = $this->createModel()
23
                                 ->where('created_at', '>=', $monthAgo)->count();
24
        $signedStatistics = $this->createModel()
25
                                 ->where('created_at', '>=', $monthAgo)
26
                                 ->select([DB::raw('COUNT(id) AS cnt'), DB::raw('DATE(created_at) as dt')])
27
                                 ->groupBy('dt')->pluck('cnt', 'dt');
28
29
        return view(Architect::template()->dashboard('members'), [
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

29
        return /** @scrutinizer ignore-call */ view(Architect::template()->dashboard('members'), [
Loading history...
30
            'total' => $total,
31
            'signed' => [
32
                'lastWeek' => $signedLastWeek,
33
                'lastMonth' => $signedLastMonth,
34
            ],
35
            'signedStatistics' => $signedStatistics,
36
        ]);
37
    }
38
39
    /**
40
     * @return User
0 ignored issues
show
Bug introduced by
The type Terranet\Administrator\Dashboard\Panels\User was not found. Did you mean User? If so, make sure to prefix the type with \.
Loading history...
41
     */
42
    protected function createModel()
43
    {
44
        $model = config('administrator.auth.model', '\App\User');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

44
        $model = /** @scrutinizer ignore-call */ config('administrator.auth.model', '\App\User');
Loading history...
45
46
        return new $model();
47
    }
48
}
49