UserRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 21 2
A sidebar() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models\Repositories;
6
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\Facades\Request as FacadeRequest;
9
use Xetaravel\Models\User;
10
11
class UserRepository
12
{
13
    /**
14
     * Find the authors of articles with most articles for the sidebar.
15
     *
16
     * @return \Illuminate\Database\Eloquent\Collection
17
     */
18
    public static function sidebar(): Collection
19
    {
20
        return User::where('blog_article_count', '>=', 1)
21
            ->take(config('xetaravel.blog.users_sidebar'))
22
            ->orderBy('blog_article_count', 'desc')
23
            ->get();
24
    }
25
26
    /**
27
     * Create a new user instance after a valid registration.
28
     *
29
     * @param array $data The data used to create the user.
30
     * @param array $providerData The additional data provided by the provider.
31
     * @param bool $provider Whether the user is registered with a Social Provider.
32
     *
33
     * @return User
34
     */
35
    public static function create(array $data, array $providerData = [], bool $provider = false): User
36
    {
37
        $ip = FacadeRequest::ip();
38
39
        $user = [
40
            'username' => $data['username'],
41
            'email' => $data['email'],
42
            'register_ip' => $ip,
43
            'last_login_ip' => $ip,
44
            'last_login_date' => now()
45
        ];
46
47
        if ($provider === false) {
48
            $user += [
49
                'password' => bcrypt($data['password'])
50
            ];
51
        } else {
52
            $user += $providerData;
53
        }
54
55
        return User::create($user);
56
    }
57
}
58