|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\User\Tasks; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\Authentication\Exceptions\UpdateResourceFailedException; |
|
6
|
|
|
use App\Containers\User\Contracts\UserRepositoryInterface; |
|
7
|
|
|
use App\Port\Task\Abstracts\Task; |
|
8
|
|
|
use Illuminate\Support\Facades\Hash; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class UpdateUserTask. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class UpdateUserTask extends Task |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var \App\Containers\User\Contracts\UserRepositoryInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
private $userRepository; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* UpdateUserTask constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param \App\Containers\User\Contracts\UserRepositoryInterface $userRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(UserRepositoryInterface $userRepository) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->userRepository = $userRepository; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param $userId |
|
35
|
|
|
* @param null $password |
|
36
|
|
|
* @param null $name |
|
37
|
|
|
* @param null $email |
|
38
|
|
|
* @param null $gender |
|
39
|
|
|
* @param null $birth |
|
40
|
|
|
* @param null $token |
|
41
|
|
|
* @param null $expiresIn |
|
42
|
|
|
* @param null $refreshToken |
|
43
|
|
|
* @param null $tokenSecret |
|
44
|
|
|
* |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
public function run( |
|
48
|
|
|
$userId, |
|
49
|
|
|
$password = null, |
|
50
|
|
|
$name = null, |
|
51
|
|
|
$email = null, |
|
52
|
|
|
$gender = null, |
|
53
|
|
|
$birth = null, |
|
54
|
|
|
$token = null, |
|
55
|
|
|
$expiresIn = null, |
|
56
|
|
|
$refreshToken = null, |
|
57
|
|
|
$tokenSecret = null |
|
58
|
|
|
) { |
|
59
|
|
|
$attributes = []; |
|
60
|
|
|
|
|
61
|
|
|
if ($password) { |
|
62
|
|
|
$attributes['password'] = Hash::make($password); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($name) { |
|
66
|
|
|
$attributes['name'] = $name; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($email) { |
|
70
|
|
|
$attributes['email'] = $email; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if ($gender) { |
|
74
|
|
|
$attributes['gender'] = $gender; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if ($birth) { |
|
78
|
|
|
$attributes['birth'] = $birth; |
|
79
|
|
|
} |
|
80
|
|
|
if ($token) { |
|
81
|
|
|
$attributes['social_token'] = $token; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($expiresIn) { |
|
85
|
|
|
$attributes['social_expires_in'] = $expiresIn; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ($refreshToken) { |
|
89
|
|
|
$attributes['social_refresh_token'] = $refreshToken; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if ($tokenSecret) { |
|
93
|
|
|
$attributes['social_token_secret'] = $tokenSecret; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// check if data is empty |
|
97
|
|
|
if (!$attributes) { |
|
|
|
|
|
|
98
|
|
|
throw new UpdateResourceFailedException('Inputs are empty.'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// updating the attributes |
|
102
|
|
|
$user = $this->userRepository->update($attributes, $userId); |
|
103
|
|
|
|
|
104
|
|
|
return $user; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.