UserRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A createAuth() 0 17 2
1
<?php
2
/**
3
 * Date: 2019/4/3 Time: 9:33
4
 *
5
 * @author  Eddy <[email protected]>
6
 * @version v1.0.0
7
 */
8
9
namespace App\Repository\Front;
10
11
use App\Model\Front\User;
12
use App\Model\Front\UserAuth;
13
14
class UserRepository
15
{
16
    public static function create($data)
17
    {
18
        $data['password'] = bcrypt($data['password']);
19
        return User::query()->create($data);
20
    }
21
22
    public static function createAuth($userId, \Overtrue\Socialite\User $user)
23
    {
24
        $type = strtolower($user->getProviderName());
25
        if (!isset(UserAuth::AUTH_TYPE_NAME[$type])) {
26
            throw new \InvalidArgumentException('三方授权类型未注册');
27
        }
28
        $data = [];
29
        $data['type'] = UserAuth::AUTH_TYPE_NAME[$type];
30
31
        $data['user_id'] = $userId;
32
        $data['openid'] = $user->getId();
33
        $data['avatar'] = (string) $user->getAvatar();
34
        $data['username'] = (string) $user->getName();
35
        $data['nick_name'] = (string) $user->getNickname();
36
        $data['email'] = (string) $user->getEmail();
37
38
        return UserAuth::query()->create($data);
39
    }
40
}
41