1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Happyr\ApiClient\Api; |
4
|
|
|
|
5
|
|
|
use Happyr\ApiClient\Assert; |
6
|
|
|
use Happyr\ApiClient\Exception; |
7
|
|
|
use Happyr\ApiClient\Model\UserManagement\User; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Tobias Nyholm <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
final class UserManagement extends HttpApi |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param string $user |
17
|
|
|
* |
18
|
|
|
* @throws Exception |
19
|
|
|
* |
20
|
|
|
* @return User|ResponseInterface |
21
|
|
|
*/ |
22
|
|
|
public function show($user) |
23
|
|
|
{ |
24
|
|
|
Assert::stringNotEmpty($user); |
25
|
|
|
|
26
|
|
|
$response = $this->httpGet('/api/user/info', ['user' => $user]); |
27
|
|
|
|
28
|
|
|
return $this->hydrateResponse($response, User::class); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $user |
33
|
|
|
* @param array $param Valid keys are email, name, gender, birthday, country |
34
|
|
|
* |
35
|
|
|
* @throws Exception |
36
|
|
|
* |
37
|
|
|
* @return User|ResponseInterface |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function update($user, $param) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
Assert::stringNotEmpty($user); |
42
|
|
|
$param['user'] = $user; |
43
|
|
|
|
44
|
|
|
$response = $this->httpPost('/api/user/update/profile', $param); |
45
|
|
|
|
46
|
|
|
return $this->hydrateResponse($response, User::class); |
47
|
|
|
} |
48
|
|
|
/** |
49
|
|
|
* @param string $user the user ID we should merge personality data to. |
50
|
|
|
* @param string $from the user ID we should merge personality data from. |
51
|
|
|
* |
52
|
|
|
* @throws Exception |
53
|
|
|
* |
54
|
|
|
* @return User|ResponseInterface |
55
|
|
|
*/ |
56
|
|
|
public function merge($user, $from) |
57
|
|
|
{ |
58
|
|
|
Assert::stringNotEmpty($user); |
59
|
|
|
Assert::stringNotEmpty($from); |
60
|
|
|
$param['user'] = $user; |
|
|
|
|
61
|
|
|
$param['from'] = $from; |
62
|
|
|
|
63
|
|
|
$response = $this->httpPost('/api/user/merge', $param); |
64
|
|
|
|
65
|
|
|
return $this->hydrateResponse($response, User::class); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.