Completed
Push — master ( d44703...10eaf5 )
by Tobias
03:10
created

UserManagement::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$param was never initialized. Although not strictly required by PHP, it is generally a good practice to add $param = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
61
        $param['from'] = $from;
62
63
        $response = $this->httpPost('/api/user/merge', $param);
64
65
        return $this->hydrateResponse($response, User::class);
66
    }
67
}
68