GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 511799...093d46 )
by Ema
02:48
created

TeamsApi::updateTeam()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient\Api;
6
7
use Pnz\MattermostClient\Exception\InvalidArgumentException;
8
use Pnz\MattermostClient\Model\Channel\Channels;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pnz\MattermostClient\Api\Channels.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use Pnz\MattermostClient\Model\Status;
10
use Pnz\MattermostClient\Model\Team\Team;
11
use Pnz\MattermostClient\Model\Team\TeamMember;
12
use Pnz\MattermostClient\Model\Team\TeamMembers;
13
use Pnz\MattermostClient\Model\Team\Teams;
14
use Pnz\MattermostClient\Model\Team\TeamStats;
15
use Psr\Http\Message\ResponseInterface;
16
17
final class TeamsApi extends HttpApi
18
{
19
    /**
20
     * Returns an team by its ID.
21
     *
22
     * @param string $id
23
     *
24
     * @return Team|ResponseInterface
25
     */
26 9
    public function getTeamById($id)
27
    {
28 9
        if (empty($id)) {
29 1
            throw new InvalidArgumentException('Id can not be empty');
30
        }
31
32 8
        $response = $this->httpGet(sprintf('/teams/%s', $id));
33
34 8
        return $this->handleResponse($response, Team::class);
35
    }
36
37
    /**
38
     * Create a team. Required parameters: 'name', 'display_name' and 'type'.
39
     *
40
     * @param array $params
41
     *
42
     * @return Team|ResponseInterface
43
     */
44 8
    public function createTeam(array $params)
45
    {
46 8
        $response = $this->httpPost('/teams',
47 8
            $params
48
        );
49
50 8
        return $this->handleResponse($response, Team::class);
51
    }
52
53
    /**
54
     * Returns a collection of teams.
55
     *
56
     * @param array $params The listing params, 'page', 'per_page'
57
     *
58
     * @return Teams|ResponseInterface
59
     */
60 8
    public function getTeams(array $params = [])
61
    {
62 8
        $response = $this->httpGet('/teams', $params);
63
64 8
        return $this->handleResponse($response, Teams::class);
65
    }
66
67
    /**
68
     * Delete a team softly and put in archived only.
69
     *
70
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D%2Fdelete
71
     *
72
     * @param string $teamId    Team GUID
73
     * @param bool   $permanent permanently delete the team, to be used for complience reasons only
74
     *
75
     * @return Status|ResponseInterface
76
     */
77 10
    public function deleteTeam(string $teamId, bool $permanent = false)
78
    {
79 10
        if (empty($teamId)) {
80 1
            throw new InvalidArgumentException('User ID can not be empty');
81
        }
82
83 9
        $pathParams = $permanent ? ['permanent' => true] : [];
84
85 9
        $response = $this->httpDelete(sprintf('/teams/%s', $teamId), [], $pathParams);
86
87 9
        return $this->handleResponse($response, Status::class);
88
    }
89
90
    /**
91
     * Returns a team given its name.
92
     *
93
     * @param string $name
94
     *
95
     * @return Team|ResponseInterface
96
     */
97 9
    public function getTeamByName($name)
98
    {
99 9
        if (empty($name)) {
100 1
            throw new InvalidArgumentException('TeamName can not be empty');
101
        }
102
103 8
        $response = $this->httpGet(sprintf('/teams/name/%s', $name));
104
105 8
        return $this->handleResponse($response, Team::class);
106
    }
107
108
    /**
109
     * Add a user to a team, with specific roles.
110
     *
111
     * @param string $teamId
112
     * @param string $userId
113
     * @param string $roles
114
     * @param array  $pathParams
115
     *
116
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1members%2Fpost
117
     *
118
     * @return TeamMember|ResponseInterface
119
     */
120 11 View Code Duplication
    public function addTeamMember($teamId, $userId, $roles = '', $pathParams = [])
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...
121
    {
122 11
        if (empty($teamId) || empty($userId)) {
123 3
            throw new InvalidArgumentException('Team ID or user ID can not be empty');
124
        }
125
126
        $body = [
127 8
            'team_id' => $teamId,
128 8
            'user_id' => $userId,
129 8
            'roles' => $roles,
130
        ];
131
132 8
        $response = $this->httpPost(sprintf('/teams/%s/members', $teamId), $body, $pathParams);
133
134 8
        return $this->handleResponse($response, TeamMember::class);
135
    }
136
137
    /**
138
     * Return the team members.
139
     *
140
     * @param string $teamId The Team ID
141
     * @param array  $params The listing params, 'page', 'per_page'
142
     *
143
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1members%2Fget
144
     *
145
     * @return TeamMembers
146
     */
147 9
    public function getTeamMembers(string $teamId, array $params = [])
148
    {
149 9
        if (empty($teamId)) {
150 1
            throw new InvalidArgumentException('TeamID can not be empty');
151
        }
152
153 8
        $response = $this->httpGet(sprintf('/teams/%s/members', $teamId), $params);
154
155 8
        return $this->handleResponse($response, TeamMembers::class);
156
    }
157
158
    /**
159
     * Remove a team member.
160
     *
161
     * @param string $teamId The team ID
162
     * @param string $userId The user ID
163
     *
164
     * https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1members~1%7Buser_id%7D%2Fdelete
165
     *
166
     * @return Status|ResponseInterface
167
     */
168 11
    public function removeTeamMember(string $teamId, string $userId)
169
    {
170 11
        if (empty($teamId) || empty($userId)) {
171 3
            throw new InvalidArgumentException('TeamID and UserId can not be empty');
172
        }
173
174 8
        $response = $this->httpDelete(sprintf('/teams/%s/members/%s', $teamId, $userId));
175
176 8
        return $this->handleResponse($response, Status::class);
177
    }
178
179
    /**
180
     * Return the list of public channels in the given team.
181
     *
182
     * @param string $teamId The team ID
183
     * @param array  $params The listing params, 'page', 'per_page'
184
     *
185
     * @return Channels|ResponseInterface
186
     */
187 9
    public function getTeamPublicChannels(string $teamId, array $params = [])
188
    {
189 9
        if (empty($teamId)) {
190 1
            throw new InvalidArgumentException('TeamID can not be empty');
191
        }
192
193 8
        $response = $this->httpGet(sprintf('/teams/%s/channels', $teamId), $params);
194
195 8
        return $this->handleResponse($response, Channels::class);
196
    }
197
198
    /**
199
     * Retrieve the team statistics.
200
     *
201
     * @param string $teamId The Team ID
202
     *
203
     * @return TeamStats|ResponseInterface
204
     */
205 9
    public function getTeamStats($teamId)
206
    {
207 9
        if (empty($teamId)) {
208 1
            throw new InvalidArgumentException('TeamID can not be empty');
209
        }
210
211 8
        $response = $this->httpGet(sprintf('/teams/%s/stats', $teamId));
212
213 8
        return $this->handleResponse($response, TeamStats::class);
214
    }
215
216
    /**
217
     * Patch a team.
218
     *
219
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1patch%2Fput
220
     *
221
     * @param string $teamId
222
     * @param array  $params
223
     *
224
     * @return Team|ResponseInterface
225
     */
226 9
    public function patchTeam(string $teamId, array $params)
227
    {
228 9
        if (empty($teamId)) {
229 1
            throw new InvalidArgumentException('TeamId can not be empty');
230
        }
231
232 8
        $response = $this->httpPut(sprintf('/teams/%s/patch', $teamId), $params);
233
234 8
        return $this->handleResponse($response, Team::class);
235
    }
236
237
    /**
238
     * Update a team.
239
     *
240
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D%2Fput
241
     *
242
     * @param string $teamId
243
     * @param array  $params, required paramaters: display_name, description, company_name, allowed_domains, invite_id, allow_open_invite
0 ignored issues
show
Documentation introduced by
There is no parameter named $params,. Did you maybe mean $params?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
244
     *
245
     * @return Team|ResponseInterface
246
     */
247 9
    public function updateTeam(string $teamId, array $params)
248
    {
249 9
        if (empty($teamId)) {
250 1
            throw new InvalidArgumentException('TeamId can not be empty');
251
        }
252
253 8
        $response = $this->httpPut(sprintf('/teams/%s', $teamId), $params);
254
255 8
        return $this->handleResponse($response, Team::class);
256
    }
257
}
258