Completed
Push — master ( f619f7...59f6c6 )
by Luca
01:16
created

ChannelModel   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 500
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 49
lcom 1
cbo 4
dl 0
loc 500
rs 8.48
c 0
b 0
f 0

49 Methods

Rating   Name   Duplication   Size   Complexity  
A createChannel() 0 4 1
A createDirectMessageChannel() 0 4 1
A createGroupMessageChannel() 0 4 1
A getChannelsListByIds() 0 4 1
A getChannelsList() 0 4 1
A getChannel() 0 4 1
A getTimezone() 0 4 1
A updateChannel() 0 4 1
A deleteChannel() 0 4 1
A patchChannel() 0 4 1
A restoreChannel() 0 4 1
A getChannelStatistics() 0 4 1
A getChannelsPinnedPosts() 0 4 1
A getChannelByName() 0 4 1
A getChannelByNameAndTeamName() 0 4 1
A getChannelMembers() 0 4 1
A addUser() 0 4 1
A getChannelMembersByIds() 0 4 1
A getChannelMember() 0 4 1
A removeUserFromChannel() 0 4 1
A updateChannelRoles() 0 4 1
A updateChannelNotifications() 0 4 1
A viewChannel() 0 4 1
A getChannelMembersForTheUser() 0 4 1
A getChannelsForUser() 0 4 1
A getUnreadMessages() 0 4 1
A convertChannelFromPublicToPrivate() 0 4 1
A getPublicChannels() 0 4 1
A getDeletedChannels() 0 4 1
A autocompleteChannels() 0 4 1
A autocompleteChannelsForSearch() 0 4 1
A searchChannels() 0 4 1
A searchArchivedChannels() 0 4 1
A searchAllPrivateAndOpenTypeChannels() 0 4 1
A searchGroupChannels() 0 4 1
A getMembersMinusGroupMembers() 0 4 1
A updateChannelPrivacy() 0 4 1
A getInformationAboutChannelModeration() 0 4 1
A updateChannelModerationSettings() 0 4 1
A getUserSidebarCategories() 0 5 1
A createUserSidebarCategory() 0 5 1
A updateUserSidebarCategories() 0 5 1
A getUserSidebarCategoryOrder() 0 5 1
A updateUserSidebarCategoryOrder() 0 5 1
A getSidebarCategory() 0 5 1
A updateSidebarCategory() 0 5 1
A deleteSidebarCategory() 0 5 1
A getChannelMembersCountsForEachGroupThatHasAtLeastOneMember() 0 4 1
A getPrivateChannels() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like ChannelModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ChannelModel, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * This Driver is based entirely on official documentation of the Mattermost Web
4
 * Services API and you can extend it by following the directives of the documentation.
5
 *
6
 * For the full copyright and license information, please read the LICENSE.txt
7
 * file that was distributed with this source code. For the full list of
8
 * contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
9
 *
10
 * God bless this mess.
11
 *
12
 * @author Luca Agnello <[email protected]>
13
 * @link https://api.mattermost.com/
14
 */
15
16
namespace Gnello\Mattermost\Models;
17
18
use Psr\Http\Message\ResponseInterface;
19
20
/**
21
 * Class ChannelModel
22
 *
23
 * @package Gnello\Mattermost\Models
24
 */
25
class ChannelModel extends AbstractModel
26
{
27
    /**
28
     * @var string
29
     */
30
    public static $endpoint = '/channels';
31
32
    /**
33
     * @param array $requestOptions
34
     * @return ResponseInterface
35
     */
36
    public function createChannel(array $requestOptions)
37
    {
38
        return $this->client->post(self::$endpoint, $requestOptions);
39
    }
40
41
    /**
42
     * @param array $requestOptions
43
     * @return ResponseInterface
44
     */
45
    public function createDirectMessageChannel(array $requestOptions)
46
    {
47
        return $this->client->post(self::$endpoint . '/direct', $requestOptions);
48
    }
49
50
    /**
51
     * @param array $requestOptions
52
     * @return ResponseInterface
53
     */
54
    public function createGroupMessageChannel(array $requestOptions)
55
    {
56
        return $this->client->post(self::$endpoint . '/group', $requestOptions);
57
    }
58
59
    /**
60
     * @param       $teamId
61
     * @param array $requestOptions
62
     * @return ResponseInterface
63
     */
64
    public function getChannelsListByIds($teamId, array $requestOptions)
65
    {
66
        return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/ids', $requestOptions);
67
    }
68
69
    /**
70
     * @param array $requestOptions
71
     * @return ResponseInterface
72
     */
73
    public function getChannelsList(array $requestOptions = [])
74
    {
75
        return $this->client->get(self::$endpoint, $requestOptions);
76
    }
77
78
    /**
79
     * @param $channelId
80
     * @return ResponseInterface
81
     */
82
    public function getChannel($channelId)
83
    {
84
        return $this->client->get(self::$endpoint . '/' . $channelId);
85
    }
86
87
    /**
88
     * @param $channelId
89
     * @return ResponseInterface
90
     */
91
    public function getTimezone($channelId)
92
    {
93
        return $this->client->get(self::$endpoint . '/' . $channelId . '/timezones');
94
    }
95
96
    /**
97
     * @param       $channelId
98
     * @param array $requestOptions
99
     * @return ResponseInterface
100
     */
101
    public function updateChannel($channelId, array $requestOptions)
102
    {
103
        return $this->client->put(self::$endpoint . '/' . $channelId, $requestOptions);
104
    }
105
106
    /**
107
     * @param $channelId
108
     * @return ResponseInterface
109
     */
110
    public function deleteChannel($channelId)
111
    {
112
        return $this->client->delete(self::$endpoint . '/' . $channelId);
113
    }
114
115
    /**
116
     * @param       $channelId
117
     * @param array $requestOptions
118
     * @return ResponseInterface
119
     */
120
    public function patchChannel($channelId, array $requestOptions)
121
    {
122
        return $this->client->put(self::$endpoint . '/' . $channelId . '/patch', $requestOptions);
123
    }
124
125
    /**
126
     * @param       $channelId
127
     * @return ResponseInterface
128
     */
129
    public function restoreChannel($channelId)
130
    {
131
        return $this->client->post(self::$endpoint . '/' . $channelId . '/restore');
132
    }
133
134
    /**
135
     * @param $channelId
136
     * @return ResponseInterface
137
     */
138
    public function getChannelStatistics($channelId)
139
    {
140
        return $this->client->get(self::$endpoint . '/' . $channelId . '/stats');
141
    }
142
143
    /**
144
     * @param $channelId
145
     * @return ResponseInterface
146
     */
147
    public function getChannelsPinnedPosts($channelId)
148
    {
149
        return $this->client->get(self::$endpoint . '/' . $channelId . '/pinned');
150
    }
151
152
    /**
153
     * @param $teamId
154
     * @param $channelName
155
     * @return ResponseInterface
156
     */
157
    public function getChannelByName($teamId, $channelName)
158
    {
159
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/name/' . $channelName);
160
    }
161
162
    /**
163
     * @param $teamName
164
     * @param $channelName
165
     * @return ResponseInterface
166
     */
167
    public function getChannelByNameAndTeamName($teamName, $channelName)
168
    {
169
        return $this->client->get(TeamModel::$endpoint . '/name/' . $teamName . self::$endpoint . '/name/' . $channelName);
170
    }
171
172
    /**
173
     * @param $channelId
174
     * @param array $requestOptions
175
     * @return ResponseInterface
176
     */
177
    public function getChannelMembers($channelId, array $requestOptions)
178
    {
179
        return $this->client->get(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
180
    }
181
182
    /**
183
     * @param       $channelId
184
     * @param array $requestOptions
185
     * @return ResponseInterface
186
     */
187
    public function addUser($channelId, array $requestOptions)
188
    {
189
        return $this->client->post(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
190
    }
191
192
    /**
193
     * @param       $channelId
194
     * @param array $requestOptions
195
     * @return ResponseInterface
196
     */
197
    public function getChannelMembersByIds($channelId, array $requestOptions)
198
    {
199
        return $this->client->post(self::$endpoint . '/' . $channelId . '/members/ids', $requestOptions);
200
    }
201
202
    /**
203
     * @param $channelId
204
     * @param $userId
205
     * @return ResponseInterface
206
     */
207
    public function getChannelMember($channelId, $userId)
208
    {
209
        return $this->client->get(self::$endpoint . '/' . $channelId . '/members/' . $userId);
210
    }
211
212
    /**
213
     * @param $channelId
214
     * @param $userId
215
     * @return ResponseInterface
216
     */
217
    public function removeUserFromChannel($channelId, $userId)
218
    {
219
        return $this->client->delete(self::$endpoint . '/' . $channelId . '/members/' . $userId);
220
    }
221
222
    /**
223
     * @param       $channelId
224
     * @param       $userId
225
     * @param array $requestOptions
226
     * @return ResponseInterface
227
     */
228
    public function updateChannelRoles($channelId, $userId, array $requestOptions)
229
    {
230
        return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/roles', $requestOptions);
231
    }
232
233
    /**
234
     * @param       $channelId
235
     * @param       $userId
236
     * @param array $requestOptions
237
     * @return ResponseInterface
238
     */
239
    public function updateChannelNotifications($channelId, $userId, array $requestOptions)
240
    {
241
        return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/notify_props', $requestOptions);
242
    }
243
244
    /**
245
     * @param       $userId
246
     * @param array $requestOptions
247
     * @return ResponseInterface
248
     */
249
    public function viewChannel($userId, array $requestOptions)
250
    {
251
        return $this->client->post(self::$endpoint . '/members/' . $userId . '/view', $requestOptions);
252
    }
253
254
    /**
255
     * @param $userId
256
     * @param $teamId
257
     * @return ResponseInterface
258
     */
259
    public function getChannelMembersForTheUser($userId, $teamId)
260
    {
261
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/members');
262
    }
263
264
    /**
265
     * @param $userId
266
     * @param $teamId
267
     * @return ResponseInterface
268
     */
269
    public function getChannelsForUser($userId, $teamId)
270
    {
271
        return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . self::$endpoint);
272
    }
273
274
    /**
275
     * @param $userId
276
     * @param $channelId
277
     * @return ResponseInterface
278
     */
279
    public function getUnreadMessages($userId, $channelId)
280
    {
281
        return $this->client->get(UserModel::$endpoint . '/' . $userId . self::$endpoint . '/' . $channelId . '/unread');
282
    }
283
284
    /**
285
     * @param $channelId
286
     * @return ResponseInterface
287
     */
288
    public function convertChannelFromPublicToPrivate($channelId)
289
    {
290
        return $this->client->post(self::$endpoint . '/' . $channelId . '/convert');
291
    }
292
293
    /**
294
     * @param       $teamId
295
     * @param array $requestOptions
296
     * @return ResponseInterface
297
     */
298
    public function getPublicChannels($teamId, array $requestOptions)
299
    {
300
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint, $requestOptions);
301
    }
302
303
    /**
304
     * @param       $teamId
305
     * @param array $requestOptions
306
     * @return ResponseInterface
307
     */
308
    public function getDeletedChannels($teamId, array $requestOptions)
309
    {
310
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/deleted', $requestOptions);
311
    }
312
313
    /**
314
     * @param       $teamId
315
     * @param array $requestOptions
316
     * @return ResponseInterface
317
     */
318
    public function autocompleteChannels($teamId, array $requestOptions)
319
    {
320
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/autocomplete', $requestOptions);
321
    }
322
323
    /**
324
     * @param       $teamId
325
     * @param array $requestOptions
326
     * @return ResponseInterface
327
     */
328
    public function autocompleteChannelsForSearch($teamId, array $requestOptions)
329
    {
330
        return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search_autocomplete', $requestOptions);
331
    }
332
333
    /**
334
     * @param       $teamId
335
     * @param array $requestOptions
336
     * @return ResponseInterface
337
     */
338
    public function searchChannels($teamId, array $requestOptions)
339
    {
340
        return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search', $requestOptions);
341
    }
342
343
    /**
344
     * @param       $teamId
345
     * @param array $requestOptions
346
     * @return ResponseInterface
347
     */
348
    public function searchArchivedChannels($teamId, array $requestOptions)
349
    {
350
        return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search_archived', $requestOptions);
351
    }
352
353
    /**
354
     * @param array $requestOptions
355
     * @return ResponseInterface
356
     */
357
    public function searchAllPrivateAndOpenTypeChannels(array $requestOptions)
358
    {
359
        return $this->client->post(self::$endpoint . '/search', $requestOptions);
360
    }
361
362
    /**
363
     * @param array $requestOptions
364
     * @return ResponseInterface
365
     */
366
    public function searchGroupChannels(array $requestOptions)
367
    {
368
        return $this->client->post('/group/search', $requestOptions);
369
    }
370
371
    /**
372
     * @param       $channelId
373
     * @param array $requestOptions
374
     * @return ResponseInterface
375
     */
376
    public function getMembersMinusGroupMembers($channelId, array $requestOptions)
377
    {
378
        return $this->client->get(self::$endpoint . $channelId . '/members_minus_group_members', $requestOptions);
379
    }
380
381
    /**
382
     * @param       $channelId
383
     * @param array $requestOptions
384
     * @return ResponseInterface
385
     */
386
    public function updateChannelPrivacy($channelId, array $requestOptions)
387
    {
388
        return $this->client->put(self::$endpoint . '/' . $channelId . '/privacy', $requestOptions);
389
    }
390
391
    /**
392
     * @param       $channelId
393
     * @return ResponseInterface
394
     */
395
    public function getInformationAboutChannelModeration($channelId)
396
    {
397
        return $this->client->get(self::$endpoint . '/' . $channelId . '/moderations');
398
    }
399
400
    /**
401
     * @param       $channelId
402
     * @param array $requestOptions
403
     * @return ResponseInterface
404
     */
405
    public function updateChannelModerationSettings($channelId, array $requestOptions)
406
    {
407
        return $this->client->put(self::$endpoint . '/' . $channelId . '/moderations/patch', $requestOptions);
408
    }
409
410
    /**
411
     * @param $teamId
412
     * @param $userId
413
     * @return ResponseInterface
414
     */
415
    public function getUserSidebarCategories($teamId, $userId)
416
    {
417
        return $this->client->put(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
418
            self::$endpoint . '/categories');
419
    }
420
421
    /**
422
     * @param       $teamId
423
     * @param       $userId
424
     * @param array $requestOptions
425
     * @return ResponseInterface
426
     */
427
    public function createUserSidebarCategory($teamId, $userId, array $requestOptions)
428
    {
429
        return $this->client->post(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
430
            self::$endpoint . '/categories', $requestOptions);
431
    }
432
433
    /**
434
     * @param       $teamId
435
     * @param       $userId
436
     * @param array $requestOptions
437
     * @return ResponseInterface
438
     */
439
    public function updateUserSidebarCategories($teamId, $userId, array $requestOptions)
440
    {
441
        return $this->client->put(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
442
            self::$endpoint . '/categories', $requestOptions);
443
    }
444
445
    /**
446
     * @param       $teamId
447
     * @param       $userId
448
     * @return ResponseInterface
449
     */
450
    public function getUserSidebarCategoryOrder($teamId, $userId)
451
    {
452
        return $this->client->get(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
453
            self::$endpoint . '/categories/order');
454
    }
455
456
    /**
457
     * @param       $teamId
458
     * @param       $userId
459
     * @param array $requestOptions
460
     * @return ResponseInterface
461
     */
462
    public function updateUserSidebarCategoryOrder($teamId, $userId, array $requestOptions)
463
    {
464
        return $this->client->put(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
465
            self::$endpoint . '/categories/order', $requestOptions);
466
    }
467
468
    /**
469
     * @param $teamId
470
     * @param $userId
471
     * @param $categoryId
472
     * @return ResponseInterface
473
     */
474
    public function getSidebarCategory($teamId, $userId, $categoryId)
475
    {
476
        return $this->client->get(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
477
            self::$endpoint . '/categories/' . $categoryId);
478
    }
479
480
    /**
481
     * @param       $teamId
482
     * @param       $userId
483
     * @param       $categoryId
484
     * @param array $requestOptions
485
     * @return ResponseInterface
486
     */
487
    public function updateSidebarCategory($teamId, $userId, $categoryId, array $requestOptions)
488
    {
489
        return $this->client->put(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
490
            self::$endpoint . '/categories/' . $categoryId, $requestOptions);
491
    }
492
493
    /**
494
     * @param       $teamId
495
     * @param       $userId
496
     * @param       $categoryId
497
     * @return ResponseInterface
498
     */
499
    public function deleteSidebarCategory($teamId, $userId, $categoryId)
500
    {
501
        return $this->client->delete(UserModel::$endpoint . '/' . $userId . TeamModel::$endpoint . '/' . $teamId .
502
            self::$endpoint . '/categories/' . $categoryId);
503
    }
504
505
    /**
506
     * @param       $channelId
507
     * @param array $requestOptions
508
     * @return ResponseInterface
509
     */
510
    public function getChannelMembersCountsForEachGroupThatHasAtLeastOneMember($channelId, array $requestOptions)
511
    {
512
        return $this->client->get(self::$endpoint . $channelId . '/member_counts_by_group', $requestOptions);
513
    }
514
515
    /**
516
     * @param       $teamId
517
     * @param array $requestOptions
518
     * @return ResponseInterface
519
     */
520
    public function getPrivateChannels($teamId, array $requestOptions = [])
521
    {
522
        return $this->client->get(TeamModel::$endpoint . $teamId . '/channels/private', $requestOptions);
523
    }
524
}
525