Issues (14)

src/Api/User.php (4 issues)

1
<?php
2
3
namespace Pixela\Api;
4
5
class User extends Api implements UserInterface
6
{
7
    /**
8
     * Create user
9
     *
10
     * @param string $agreeTermsOfService
11
     * @param string $notMinor
12
     * @return bool
13
     * @throws \GuzzleHttp\Exception\GuzzleException
14
     */
15
    public function create($agreeTermsOfService = 'yes', $notMinor = 'yes')
16
    {
17
        $options = array(
18
            'body' => json_encode(array(
19
                'username' => $this->getClient()->getUsername(),
20
                'token' => $this->getClient()->getToken(),
21
                'agreeTermsOfService' => $agreeTermsOfService,
22
                'notMinor' => $notMinor
23
            )),
24
        );
25
26
        $response = $this->getClient()->getHttpClient()->request('post', Api::API_BASE_ENDPOINT . '/users', $options);
0 ignored issues
show
The assignment to $response is dead and can be removed.
Loading history...
27
28
        return true;
29
    }
30
31
    /**
32
     * Update user
33
     *
34
     * @param $newToken
35
     * @return string
36
     * @throws \GuzzleHttp\Exception\GuzzleException
37
     */
38
    public function update($newToken)
39
    {
40
        $uri = Api::API_BASE_ENDPOINT . '/users/' . $this->getClient()->getUsername();
41
42
        $options = array(
43
            'headers' => array(
44
                'X-USER-TOKEN' => $this->getClient()->getToken()
45
            ),
46
            'body' => json_encode(
47
                array(
48
                    'newToken' => $newToken
49
                )
50
            )
51
        );
52
53
        $response = $this->getClient()->getHttpClient()->request('put', $uri, $options);
0 ignored issues
show
The assignment to $response is dead and can be removed.
Loading history...
54
55
        $this->getClient()->setToken($newToken);
56
57
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type string.
Loading history...
58
    }
59
60
    /**
61
     * Delete user
62
     *
63
     * @return bool
64
     * @throws \GuzzleHttp\Exception\GuzzleException
65
     */
66
    public function delete()
67
    {
68
        $uri = Api::API_BASE_ENDPOINT . '/users/' . $this->getClient()->getUsername();
69
70
        $options = array(
71
            'headers' => array(
72
                'X-USER-TOKEN' => $this->getClient()->getToken()
73
            )
74
        );
75
76
        $response = $this->getClient()->getHttpClient()->request('delete', $uri, $options);
0 ignored issues
show
The assignment to $response is dead and can be removed.
Loading history...
77
78
        return true;
79
    }
80
}
81