Completed
Push — master ( d86698...3d0fab )
by
unknown
03:08
created

UpdateUserSocialProfileTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Containers\SocialAuth\Tasks;
4
5
use App\Containers\User\Data\Repositories\UserRepository;
6
use App\Ship\Exceptions\UpdateResourceFailedException;
7
use App\Ship\Parents\Tasks\Task;
8
9
/**
10
 * Class UpdateUserSocialProfileTask.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class UpdateUserSocialProfileTask extends Task
15
{
16
17
    protected $repository;
18
19
    public function __construct(UserRepository $repository)
20
    {
21
        $this->repository = $repository;
22
    }
23
24
    /**
25
     * @param      $userId
26
     * @param null $token
27
     * @param null $expiresIn
28
     * @param null $refreshToken
29
     * @param null $tokenSecret
30
     * @param null $provider
31
     * @param null $avatar
32
     * @param null $avatar_original
33
     * @param null $socialId
34
     * @param null $nickname
35
     * @param null $name
36
     * @param null $email
37
     *
38
     * @return  mixed
39
     * @throws  UpdateResourceFailedException
40
     */
41
    public function run(
42
        $userId,
43
        $token = null,
44
        $expiresIn = null,
45
        $refreshToken = null,
46
        $tokenSecret = null,
47
        $avatar = null,
48
        $avatar_original = null,
49
        $provider = null,
50
        $socialId = null,
51
        $nickname = null,
52
        $name = null,
53
        $email = null
54
    ) {
55
        $attributes = [];
56
57
        if ($token) {
58
            $attributes['social_token'] = $token;
59
        }
60
61
        if ($expiresIn) {
62
            $attributes['social_expires_in'] = $expiresIn;
63
        }
64
65
        if ($refreshToken) {
66
            $attributes['social_refresh_token'] = $refreshToken;
67
        }
68
69
        if ($tokenSecret) {
70
            $attributes['social_token_secret'] = $tokenSecret;
71
        }
72
73
        if ($provider) {
74
            $attributes['social_provider'] = $provider;
75
        }
76
77
        if ($avatar) {
78
            $attributes['social_avatar'] = $avatar;
79
        }
80
81
        if ($avatar_original) {
82
            $attributes['social_avatar_original'] = $avatar_original;
83
        }
84
85
        if ($socialId) {
86
            $attributes['social_id'] = $socialId;
87
        }
88
89
        if ($nickname) {
90
            $attributes['social_nickname'] = $nickname;
91
        }
92
93
        if ($name) {
94
            $attributes['name'] = $name;
95
        }
96
97
        if ($email) {
98
            $attributes['email'] = $email;
99
        }
100
101
        // check if data is empty
102
        if (empty($attributes)) {
103
            throw new UpdateResourceFailedException('Inputs are empty.');
104
        }
105
106
        // updating the attributes
107
        $user = $this->repository->update($attributes, $userId);
108
109
        return $user;
110
    }
111
112
113
}
114