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.

TeamsApi::deleteTeam()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
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;
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
     * @return Team|ResponseInterface
41
     */
42 8
    public function createTeam(array $params)
43
    {
44 8
        $response = $this->httpPost(
45 8
            '/teams',
46 8
            $params
47
        );
48
49 8
        return $this->handleResponse($response, Team::class);
50
    }
51
52
    /**
53
     * Returns a collection of teams.
54
     *
55
     * @param array $params The listing params, 'page', 'per_page'
56
     *
57
     * @return Teams|ResponseInterface
58
     */
59 8
    public function getTeams(array $params = [])
60
    {
61 8
        $response = $this->httpGet('/teams', $params);
62
63 8
        return $this->handleResponse($response, Teams::class);
64
    }
65
66
    /**
67
     * Delete a team softly and put in archived only.
68
     *
69
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D%2Fdelete
70
     *
71
     * @param string $teamId    Team GUID
72
     * @param bool   $permanent permanently delete the team, to be used for complience reasons only
73
     *
74
     * @return Status|ResponseInterface
75
     */
76 10
    public function deleteTeam(string $teamId, bool $permanent = false)
77
    {
78 10
        if (empty($teamId)) {
79 1
            throw new InvalidArgumentException('User ID can not be empty');
80
        }
81
82 9
        $pathParams = $permanent ? ['permanent' => true] : [];
83
84 9
        $response = $this->httpDelete(sprintf('/teams/%s', $teamId), [], $pathParams);
85
86 9
        return $this->handleResponse($response, Status::class);
87
    }
88
89
    /**
90
     * Returns a team given its name.
91
     *
92
     * @param string $name
93
     *
94
     * @return Team|ResponseInterface
95
     */
96 9
    public function getTeamByName($name)
97
    {
98 9
        if (empty($name)) {
99 1
            throw new InvalidArgumentException('TeamName can not be empty');
100
        }
101
102 8
        $response = $this->httpGet(sprintf('/teams/name/%s', $name));
103
104 8
        return $this->handleResponse($response, Team::class);
105
    }
106
107
    /**
108
     * Add a user to a team, with specific roles.
109
     *
110
     * @param string $teamId
111
     * @param string $userId
112
     * @param string $roles
113
     * @param array  $pathParams
114
     *
115
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1members%2Fpost
116
     *
117
     * @return TeamMember|ResponseInterface
118
     */
119 11
    public function addTeamMember($teamId, $userId, $roles = '', $pathParams = [])
120
    {
121 11
        if (empty($teamId) || empty($userId)) {
122 3
            throw new InvalidArgumentException('Team ID or user ID can not be empty');
123
        }
124
125
        $body = [
126 8
            'team_id' => $teamId,
127 8
            'user_id' => $userId,
128 8
            'roles' => $roles,
129
        ];
130
131 8
        $response = $this->httpPost(sprintf('/teams/%s/members', $teamId), $body, $pathParams);
132
133 8
        return $this->handleResponse($response, TeamMember::class);
134
    }
135
136
    /**
137
     * Return the team members.
138
     *
139
     * @param string $teamId The Team ID
140
     * @param array  $params The listing params, 'page', 'per_page'
141
     *
142
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1members%2Fget
143
     */
144 9
    public function getTeamMembers(string $teamId, array $params = []): TeamMembers
145
    {
146 9
        if (empty($teamId)) {
147 1
            throw new InvalidArgumentException('TeamID can not be empty');
148
        }
149
150 8
        $response = $this->httpGet(sprintf('/teams/%s/members', $teamId), $params);
151
152 8
        return $this->handleResponse($response, TeamMembers::class);
153
    }
154
155
    /**
156
     * Get a team member from the system given a Team and User IDs.
157
     *
158
     * @param string $teamId The Team GUID
159
     * @param string $userId The User GUID
160
     */
161 11
    public function getTeamMember(string $teamId, string $userId): TeamMember
162
    {
163 11
        if (empty($teamId) || empty($userId)) {
164 3
            throw new InvalidArgumentException('TeamID and UserId can not be empty');
165
        }
166
167 8
        $response = $this->httpGet(sprintf('/teams/%s/members/%s', $teamId, $userId));
168
169 8
        return $this->handleResponse($response, TeamMember::class);
170
    }
171
172
    /**
173
     * Remove a team member.
174
     *
175
     * @param string $teamId The team ID
176
     * @param string $userId The user ID
177
     *
178
     * https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1members~1%7Buser_id%7D%2Fdelete
179
     *
180
     * @return Status|ResponseInterface
181
     */
182 11
    public function removeTeamMember(string $teamId, string $userId)
183
    {
184 11
        if (empty($teamId) || empty($userId)) {
185 3
            throw new InvalidArgumentException('TeamID and UserId can not be empty');
186
        }
187
188 8
        $response = $this->httpDelete(sprintf('/teams/%s/members/%s', $teamId, $userId));
189
190 8
        return $this->handleResponse($response, Status::class);
191
    }
192
193
    /**
194
     * Return the list of public channels in the given team.
195
     *
196
     * @param string $teamId The team ID
197
     * @param array  $params The listing params, 'page', 'per_page'
198
     *
199
     * @return Channels|ResponseInterface
200
     */
201 9
    public function getTeamPublicChannels(string $teamId, array $params = [])
202
    {
203 9
        if (empty($teamId)) {
204 1
            throw new InvalidArgumentException('TeamID can not be empty');
205
        }
206
207 8
        $response = $this->httpGet(sprintf('/teams/%s/channels', $teamId), $params);
208
209 8
        return $this->handleResponse($response, Channels::class);
210
    }
211
212
    /**
213
     * Retrieve the team statistics.
214
     *
215
     * @param string $teamId The Team ID
216
     *
217
     * @return TeamStats|ResponseInterface
218
     */
219 9
    public function getTeamStats($teamId)
220
    {
221 9
        if (empty($teamId)) {
222 1
            throw new InvalidArgumentException('TeamID can not be empty');
223
        }
224
225 8
        $response = $this->httpGet(sprintf('/teams/%s/stats', $teamId));
226
227 8
        return $this->handleResponse($response, TeamStats::class);
228
    }
229
230
    /**
231
     * Patch a team.
232
     *
233
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D~1patch%2Fput
234
     *
235
     * @return Team|ResponseInterface
236
     */
237 9
    public function patchTeam(string $teamId, array $params)
238
    {
239 9
        if (empty($teamId)) {
240 1
            throw new InvalidArgumentException('TeamId can not be empty');
241
        }
242
243 8
        $response = $this->httpPut(sprintf('/teams/%s/patch', $teamId), $params);
244
245 8
        return $this->handleResponse($response, Team::class);
246
    }
247
248
    /**
249
     * Update a team.
250
     *
251
     * @see https://api.mattermost.com/v4/#tag/teams%2Fpaths%2F~1teams~1%7Bteam_id%7D%2Fput
252
     *
253
     * @param array $params Required parameters are: display_name, description, company_name, allowed_domains, invite_id, allow_open_invite
254
     *
255
     * @return Team|ResponseInterface
256
     */
257 9
    public function updateTeam(string $teamId, array $params)
258
    {
259 9
        if (empty($teamId)) {
260 1
            throw new InvalidArgumentException('TeamId can not be empty');
261
        }
262
263 8
        $response = $this->httpPut(sprintf('/teams/%s', $teamId), $params);
264
265 8
        return $this->handleResponse($response, Team::class);
266
    }
267
}
268