Passed
Push — master ( 48c78c...6f5874 )
by Darko
06:40
created

SignupStat   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUsersByMonth() 0 3 1
A insertUsersByMonth() 0 5 2
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
8
class SignupStat extends Model
9
{
10
    use HasFactory;
11
12
    protected $guarded = [];
13
14
    public static function insertUsersByMonth(): void
15
    {
16
        $users = User::query()->whereNotNull('created_at')->where('created_at', '<>', '0000-00-00 00:00:00')->selectRaw("DATE_FORMAT(created_at, '%M %Y') as mth, COUNT(id) as num")->groupBy(['mth'])->orderByDesc('created_at')->get();
0 ignored issues
show
Bug introduced by
'created_at' of type string is incompatible with the type Closure|Illuminate\Datab...\Database\Query\Builder expected by parameter $column of Illuminate\Database\Query\Builder::orderByDesc(). ( Ignorable by Annotation )

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

16
        $users = User::query()->whereNotNull('created_at')->where('created_at', '<>', '0000-00-00 00:00:00')->selectRaw("DATE_FORMAT(created_at, '%M %Y') as mth, COUNT(id) as num")->groupBy(['mth'])->orderByDesc(/** @scrutinizer ignore-type */ 'created_at')->get();
Loading history...
17
        foreach ($users as $user) {
18
            self::updateOrCreate(['month' => $user->mth], ['signups' => $user->num]);
19
        }
20
    }
21
22
    public static function getUsersByMonth(): array
23
    {
24
        return self::query()->select(['month', 'signups'])->get()->toArray();
25
    }
26
}
27